dongpa3109 2016-05-11 11:38
浏览 98
已采纳

我想在上传时重命名文件以避免覆盖[重复]

This question already has an answer here:

I want to rename the file while uploading to avoid overwriting of files, I have following code, Please suggest code to avoid overwriting.

$path = "admin/uploads/resume/";
    if (!file_exists($path))
        mkdir($path, 0, true);
    $img_name = $_FILES['file']['name'];
    $img_tmp_name = $_FILES['file']['tmp_name'];
    $img_path = $img_name;
    move_uploaded_file($img_tmp_name, "admin/uploads/resume/" . $img_path);

    $img_name = $_FILES['file']['name'];
</div>
  • 写回答

1条回答 默认 最新

  • doufeng1249 2016-05-11 11:39
    关注

    Try a time() with the file name. to avoid overwriting.

    try this.

    $img_name = time()."_".$_FILES['file']['name'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?