Link to home
Start Free TrialLog in
Avatar of cabrera48
cabrera48

asked on

Unable to get a hold of temp file on PHP file upload

After uploading a file to my server, I can't get a hold of it with the move_uploaded_file() function.

If I do a print_f($_FILES)  after the upload, I get the following:

Array
(
    [FileUpload1_File] => Array
        (
            [name] => cat_lvl1_default_banner.gif
            [type] => image/gif
            [tmp_name] => C:\apps\temp_file_upload\phpFE5F.tmp
            [error] => 0
            [size] => 15281
        )

)

So it seems the upload was successful, no errors (0), and the temp file should be in "C:\apps\temp_file_upload\phpFE5F.tmp", but when I use:

move_uploaded_file($_FILES['FileUpload1_File']['tmp_name'], $new_location);

it fails. To debug, I check for is_writable([$new_location directory here]) and it is fine, I was also able to create a new file in this location manually by doing touch($new_location), so $new_location don't seem to be the problem.

In the other hand, when I tried is_uploaded_file($_FILES['FileUpload1_File']['tmp_name']) I get a false. So for some reason the file is "missing" from its temp location. This temp location folder has the permission set to be writable by all users, so I really don't know why the temp file is not there, or is not accessible to the is_uploaded_file() command.

I also tried copy($_FILES['FileUpload1_File']['tmp_name'], $new_location) instead of  move_uploaded_file(), but I get the following error:
copy(C:\apps\temp_file_upload\phpC221.tmp) [function.copy]: failed to open stream: No such file or directory

I'm thinking this is a Windows Vista issue, I'll try in a linux box, but does anybody know how can I fix this?
Avatar of Rurne
Rurne
Flag of United States of America image

Check your php.ini.  If you're configured using safe_mode_exec_dir or open_basedir, you will need to add "c:\apps\temp_file_upload" to the appropriate path.

http://us2.php.net/manual/en/features.file-upload.common-pitfalls.php
http://us2.php.net/manual/en/ini.sect.safe-mode.php


If neither of those are enabled, then does this fail for any file?  You may also want to check your php.ini for post_max_size and upload_max_filesize; if these are too small, PHP may secretly be discarding the file before it reads the entire POST request, so while it has the tmp_name in the $_FILES superglobal, the file never got written to disc.

http://us2.php.net/manual/en/ini.core.php#ini.post-max-size
http://us2.php.net/manual/en/ini.core.php#ini.upload-max-filesize
Avatar of cabrera48
cabrera48

ASKER

Thanks Rurne,

But still not working. safe_mode_exec_dir and open_basedir are off and not set, the file sizes I am uploading are small: less than 20K, and post_max_size and upload_max_filesize are at least 2M and up.

I wish I could get low level error messages from PHP about the failure to write from memory to disk and the reason why, is there a way to do that?
Question,

When there is a file upload, and nothing gets done afterwards (meaning no move_uploaded_file() or rename() command is run on those files), how long will the temp files are normally kept in the temp folder?
ASKER CERTIFIED SOLUTION
Avatar of Rurne
Rurne
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all the information,

I just figure it out, the problem is that I was relying on a tool to auto-generate HTML and database insert and update pages (CodeCharge), and in their efforts to make this easier for users, they do some sort of manipulation of the temp/ and final folder destinations for file uploads. If I manually add my own input field independent from those auto-generated by the tool it works as it should.

Sorry about all the confusion, but thanks anyways for all the help.