使用move_uploaded_file在PHP中重命名上载的文件

使用move_uploaded_file在PHP中重命名上载的文件,php,forms,file-upload,Php,Forms,File Upload,我有这个代码,想重命名上传的图像的名称 <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploadedfile" accept="image/*" capture> <input type="submit" value="Upload"> </form> <?php $t

我有这个代码,想重命名上传的图像的名称

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="uploadedfile" accept="image/*" capture>
    <input type="submit" value="Upload">
</form>

<?php 
    $target_path = "upload/";

    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded";
    } else {
        echo "There was an error uploading the file, please try again!";
    }
?>


我能做什么?

当使用
移动上传的文件($filename,$destination)
时,可以在目标位置指定文件名

$target_path = "upload/";
$target_filename = 'filename.xyz'
$target_path = $target_path . $target_filename); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ".  $target_filename). 
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}

参见文档中的

。。。只需调整
$target\u路径
…哇,我正在寻找上传脚本。谢谢