PHP File Upload, files disappearing from /tmp before move_uploaded_files

33,761

Solution 1

1) Are the post_max_size and upload_max_filesize holding higher value than the size of the file you are trying to upload?

2) Does your uploading script take longer time to execute than the value of the max_execution_time variable allows?

3) I assume your uploading script doesn't consume as much memory as the memory_limit variable allows. When the client is uploading the file to the server, then the server is probably holding some of it in memory while doing so. I'm not sure if it somehow affects the limit of the memory_limit variable in php.ini.

These variables can be changed in php.ini and/or .htaccess or with ini_set().

Hope that helps.

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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 )
Share:
33,761
Bowen
Author by

Bowen

Updated on November 27, 2020

Comments

  • Bowen
    Bowen over 3 years

    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 cannot find the tmp file in the tmp folder. But I KNOW that it is being put there, but is removed before move_upload_file() can deal with it in my script. I know it is being put there since I can see a file in there when a large file is being posted to the server.

    Also $_FILEScontains correct details for the file I have just uploaded.

    Had anyone have any idea why the temporary file is being removed from /tmp before I have a chance to handle it?

    Here is the basic code that I am using.

    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_file))
    {
        $result['error'] = 'false';
        $result['file_loc'] = $upload_file;
    }
    else
    {
        $result['error'] = 'true';
    }
    

    The output of print_r($_FILES) looks like

    [userfile] => Array
    (
        [name] => switchsolo.png
        [type] => image/png
        [tmp_name] => /tmp/phpIyKRl5
        [error] => 0
        [size] => 6690
    )
    

    But /tmp/phpIyKRl5 simply isn't there.