File Upload not in /tmp

前端 未结 1 821
陌清茗
陌清茗 2021-02-13 19:16

This sounds like a stupid question but, after uploading a file the file isnt in the location php said it would be.

First the simple test page:



        
相关标签:
1条回答
  • 2021-02-13 19:39

    The temporary file is deleted when the PHP script that received it has finished running : it is just a temporary file.

    The PHP script to which you are posting the form -- upload.php -- should move the temporary file to a non-temporary location, using move_uploaded_file()


    Basically, the idea is :

    • The user uploads a file to your script,
      • That file is stored in a temporary lcoation.
    • Your script works on that file :
      • Checks if the file is OK (content-type, size, ...)
    • And if the file is OK, your script moves it to the permanent storage directory (whereever you want)

    If the upload doesn't finish successfully, or if you don't move the file somewhere else, the temporary file is automatically deleted.


    As a reference, you should read the following section of the manual : Handling file uploads - POST method uploads

    Quoting the part of it which is related to your problem :

    The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

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