Re: Query regarding temporarily-uploaded files

From: Date: Wed, 10 Jul 2013 19:27:01 +0000
Subject: Re: Query regarding temporarily-uploaded files
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-321601@lists.php.net to get a copy of this message
On 7/10/2013 2:15 PM, Ajay Garg wrote:
Thanks Jim and Matijn for the quick replies. I will try to have a workaround. On Wed, Jul 10, 2013 at 11:09 PM, Matijn Woudt <tijnema@gmail.com> wrote:
On Wed, Jul 10, 2013 at 7:21 PM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
Hi all. I have a requirement, wherein I need to allow vanilla uploads of files to a HTTPD server. Any client can upload any number of files (one at a time). Also, there is just one directory, where the files get stored "finally" (that is, after being copied from the temporary location, via "move_uploaded_file") Also, I have been able to get the simple file uploading running via PHP, by picking up one of the numerous "Hello World" examples available :) Now, I am facing the following use-case :: 1) User 1 starts uploading a large file, say "big_file.avi". 2) Meanwhile, user 2 also starts uploading a (different) file, but with the same name "big_file.avi". In an ideal scenario, user 2 should be prompted with a message, that a file of the same name is already being uploaded by someone else somewhere. Is there a way to do this? ( Note that, had the user 2 started uploading AFTER user 1 had finished with the upload, we could probably modify the PHP-script at the sever-side, to let user-2 know that a file of the same name already exits. But I am failing to find a solution, when the user 2 starts the upload WHILE the large file of user 1 is in the process of completing uploading). Any way the issue may be solved? I will be grateful for any pointers :) Regards, Ajay
Hi, This is not possible with PHP, PHP will not know about the file until the upload is completed. You can use HTML5 or flash(not recommended) for an alternative way of uploading, and then you can check the file name in advance. - Matijn
As Matijn said, you don't know the name until your php processes the file that has been uploaded alreaday. But my solution will work for you - you just have to save it under the temp name until the user responds to your message and request for a new title. You may have to run a periodic script to clean up any files with your temp names that the user declined to re-name for you. I'd make up a temp name with some special prefix so that you can find and delete them.


« previous php.general (#321601) next »