Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set upload_tmp_dir to a dir on non-PHP drive?

PHP experts, I've been working on this problem for about a day and a half, and I'm at a loss. If I'm right, I've discovered an arguably huge oversight in PHP.. one I can't believe isn't causing problems for others, and while I've found others having the same problem via Google, all of them have accepted defeat. One even filed a bug with PHP, and it was eventually closed due to lack of activity.

I'm running PHP 5.3 w/ Apache in a WAMP stack.

I'm doing a simple file upload (followed by a move from the tmp location), and for security and speed reasons, I'd like the initial upload temp directory (upload_tmp_dir) to be on a different disk where the file will end up after the move, which happens to be a network share. Z:\temp. Normally, it resides on the same disk as PHP, but this would mean that I have to upload a potentially large file, then wait for it to copy to another disk.. rather than just upload it to the other disk AS the temp, and perform a quick move.

example:

//upload_tmp_dir = Z:\Temp (set in php.ini)
$targetpath = Z:\Data\pdfs (final destination)
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $targetpath);

Theoretically, this should upload the file temporarily to Z:\Temp, then once it completes without errors, move it to its' final destination of Z:\Data\pdfs\filename.pdf.

I've confirmed that file uploading and moving works as long as upload_tmp_dir is on the same drive PHP is.. i.e. C:\MyTemp, but will NOT work if I traverse to a different drive like Z:\Temp. The value I specified in php.ini for upload_tmp_dir is simply ignored, and the file gets stored in C:\Windows\Temp if I try to traverse to a different drive/partition. Seems to make no difference that it's a mapped drive. Permissions are all set correctly, both share and security have Everyone allowed (chmod 777 equivalent).

I've read in multiple locations that "PHP" and specifically move_uploaded_file() "has trouble with traversing drives". This is obviously for security reasons I'd assume, but it doesn't seem it can be overridden anywhere. However, with an increasing number of servers using virtualization and SSD's with limited space, I don't understand how this is possible. If one was running a site with several hundred users uploading files at a time, how does it make sense that the temporary files (which could be huge) MUST reside on C:\ where PHP is?? Have any of you dealt with this before or have any tips?

I keep assuming it's a permissions issue and so I've looked into other PHP and Apache settings which might be limiting the access, but even setting all the paths in open_base_dir for example doesn't seem to help anything.

Some posts I found outlining the same or similar issues:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_21190386.html

https://serverfault.com/questions/128017/php-ignores-upload-tmp-dir

https://bugs.php.net/bug.php?id=44420

like image 555
Drew Alden Avatar asked Dec 31 '25 05:12

Drew Alden


1 Answers

This guys says:

mapped drives are user specific, the webserver, and consequentially php, run under a different username

http://forums.phpfreaks.com/index.php?topic=175349.0

like image 120
somedev Avatar answered Jan 02 '26 18:01

somedev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!