PHP File Upload, files disappearing from /tmp before move_uploaded_files

前端 未结 14 1979
独厮守ぢ
独厮守ぢ 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:23

    Try to comment out PrivateTmp=true in in /etc/systemd/system/multi-user.target.wants/apache2.service After restarting Apache, it will always use system's temporary folder, not a relative one per session.

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

    I was trying out http://www.w3schools.com/php/php_file_upload.asp And I stumbled across the same bug.

    In my case, adding a "./" before the $destination solved the problem.

    bool move_uploaded_file ( string $filename , string $destination )
    
    0 讨论(0)
  • 2021-02-13 03:27

    Are you 100% sure that the file actually is created in /tmp? If you don't have write permission (or the user the script runs as) the file wont be written to /tmp but (I'm guessing) you'll see it during the upload although it's not actually there when the upload finishes.

    Edit: $_FILES['file']['error'] - Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. So check your PHP-version. If it's below 5.1 write to disk might be your problem.

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

    I had the same problem, where 'tmp_name' would say it is being stored in '/private/var/tmp/' but the file would not exist there.

    I had to add "E" to my "variables order" in php.ini ; variables_order Default Value: "EGPCS"

    Hope this helps.

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

    Your form should use a tag like this:

    <form method="post" enctype="multipart/form-data" action="...">
    

    Use multiple/form-data as enctype.

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

    I was just having this issue as well, came across this website for a solution - did not get it tho ;)

    I was getting the correct info when viewing print_r($_FILES) but was unable to execute move_uploaded_file...

    I solved the issue by checking the $upload_file path attribute in the move_uploaded_file function - make sure it is correct otherwise it will not work (mine was incorrect).

    Also, the file in the temp location gets removed automatically, I think that is the way PHP works.

    I hope this helped.

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