PHP File Upload, files disappearing from /tmp before move_uploaded_files

前端 未结 14 1995
独厮守ぢ
独厮守ぢ 2021-02-13 03:09

I have a very basic upload script, probably lifted straight off the php.net/move_upload_files function page.

move_uploaded_file() is failed because it canno

相关标签:
14条回答
  • 2021-02-13 03:12

    It may also be that you destination folder does not exists or you don't have write permission.

    0 讨论(0)
  • 2021-02-13 03:13

    Simple test to do right before the move_uploaded_file() function:

    if (!file_exists("upload")) {
      if (mkdir("upload")) {
        echo "Upload directory created!";
      }
      else {
        die( "Invalid upload directory!" );
      }
    }
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
    
    0 讨论(0)
  • 2021-02-13 03:20

    The file is removed after the script finishes executing. If you run your script, and then check the /tmp/ folder, the file will not be there no matter what.

    0 讨论(0)
  • 2021-02-13 03:20

    You are using the return value of move_uploaded_file() the wrong way round:

    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_file))
    {
        $result['error'] = 'true';
    }
    else
    {
        $result['error'] = 'false';
        $result['file_loc'] = $upload_file;
    }
    
    0 讨论(0)
  • 2021-02-13 03:23

    For future reference this can also happen when Apache does not have access to the destination directory (Remember to change the ACLs !!).

    0 讨论(0)
  • 2021-02-13 03:23

    I've had this problem myself. In my case php was uploading to the wrong tmp folder. Instead of using the domains tmp folder (in a virtual host on plesk) it was uploading straight to the OS temporary folder.

    Check the settings of your temporary folders

    0 讨论(0)
提交回复
热议问题