tags:

views:

142

answers:

1

I want to rotate the location where temporary files are written however it is my understanding that the PHP script wont execute until after the full post is already completed. By that time the file is already written to the default temp location from the configuration file which is loaded in at the time apache is spawned and the php module is loaded. Any ideas?

A: 

As you mention, it isn't possible to change it dynamically since the upload is completed before the page executes -- i.e. no fancy ini_set calls can be made.

A possible workaround:

You could set the temporary upload location in your php.ini file to point to a symlink (/tmp/myuploads) that in turn points to one of your chosen upload locations (/mnt/uploadstore_1/).

You can then have the PHP file that handles the upload change the symlink location to a new location each time it runs ( basically the equivalent of a 'rm /tmp/myuploads && ln -s /mnt/uploadstore_2/ /tmp/myuploads').

This should make sure that the upload that comes next ends up in your next-in-line chosen location.

Jeevan
The only problem is if there are a bunch of uploads occuring at once this wont work becuase it will break previously uploaded files. It only works if you have a stopping point where you can safely repoint the symlink however if there was a safe point there would be no need for the symlink as its needed to reduce disk load. The only real solution might be external to PHP.
Derek
Yes, that is the problem with the symlink technique..A simple perl script could do the job of handling the upload though. There is a sample upload handler here:http://www.sitepoint.com/article/uploading-files-cgi-perl/2/Good luck!
Jeevan