【问题标题】:How to rename a file being uploaded如何重命名正在上传的文件
【发布时间】:2019-08-31 16:54:06
【问题描述】:

我正在尝试重命名已上传的文件。

move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath . $newfilename)

我得到的是将$newfilename 附加到原始文件名,而不是替换它。 我做错了什么?

【问题讨论】:

    标签: php file upload rename


    【解决方案1】:

    解决了。我将 dir+filename 存储在 [$targetFilePath] ^^;

    【讨论】:

      【解决方案2】:

      你可以使用下面的代码

      $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);
      

      【讨论】:

      • 谢谢,但我在生成新名称时没有问题,我的问题是当我上传文件时:新名称附加到原始名称。即 oldname.jpgnewname.jpg
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 2015-03-16
      • 1970-01-01
      相关资源
      最近更新 更多