[英]How to rename a file being uploaded
I'm trying to rename a file that's uploaded.我正在尝试重命名已上传的文件。
move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath . $newfilename)
What I get is to have $newfilename
appended to the original file name, not to replace it.我得到的是将
$newfilename
附加到原始文件名,而不是替换它。 What I am doing wrong?我做错了什么?
You can use the below code您可以使用以下代码
$UploadImage=$_FILES['file']['name'];
$EmpName=explode(".",$UploadImage);
$Exp=$EmpName[1];
$ImageName="upload/".md5(date("d-m-y H:i:s")).".".$Exp;
move_uploaded_file($_FILES['file']['tmp_name'],$ImageName);
Solved.解决了。 I was storing dir+filename in [$targetFilePath] ^^;
我将 dir+filename 存储在 [$targetFilePath] ^^;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.