我有这个非常基本的文件上传脚本:
$prefix = "sitename";
$targetPath = "/uploads/sitename/"
$prefix = $prefix . "_";
$filename = $prefix . md5(basename($_FILES['image']['name'])) . md5(time()) . rand(11111,99999);
if(move_uploaded_file($_FILES['image']['tmp_name '], $targetPath)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
但我需要将图片重命名为$filename
,然后再移至$targetPath
中设置的位置。我该怎么办?
答案 0 :(得分:2)
您可以在move_uploaded_file
的第二个参数中指定新文件名。
示例:强>
move_uploaded_file($_FILES['image']['tmp_name'], $targetPath . $filename);