[PHP] Query regarding temporarily-uploaded files
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query regarding temporarily-uploaded files
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 wrote: > > > > On Wed, Jul 10, 2013 at 7:21 PM, Ajay Garg 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 > -- Regards, Ajay
Re: [PHP] Query regarding temporarily-uploaded files
Thanks Jim and Anthony. Jim, You are right, your solution is doable. But one thing I am a little skeptical about, is what would be the percentage of the people willing to suggest a new name "immediately", versus the percentage of people who would like to cancel the current upload, and come back "later" after walking and coming up with a new name. Anyhow, let me sleep over it :) Anthony, your solution is really a special case of Jim's solution :) Thanks guys for the quick replies; I am obliged, really. On Thu, Jul 11, 2013 at 12:59 AM, Anthony Wlodarski wrote: > Is there anything that would prevent you from somehow uniquely knowing who > the user is uploading the file. For example you mentioned "client'. If > you know > who the client is you can append that to the filename or prepend it, for > the > destination string (second parameter to the function call). That way it > is unique > to that client. > > -Anthony > > > On Wed, Jul 10, 2013 at 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 wrote: >> >> > >> > >> > >> > On Wed, Jul 10, 2013 at 7:21 PM, Ajay Garg >> 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 >> > >> >> >> >> -- >> Regards, >> Ajay >> > > > > -- > Anthony W. > ant92...@gmail.com > -- Regards, Ajay
[PHP] How to send "post"-variables in a "Location" header
Hi all. I have a scenario, wherein I need to do something like this :: ### $original_url = "/autologin.php"; $username = "ajay"; $password = "garg"; header('Location: ' . $original_url); ### As can be seen, I wish to redirect to the URL "autologin.php". Additionally, I wish to pass two POST key-value pairs :: "user=ajay" and "password=garg" (I understand that passing GET key-value pairs is trivial). Is it even possible? If yes, I will be grateful if someone could let me know how to redirect to a URL, passing the POST key-value pairs as necessary. Looking forward to a reply :) -- Regards, Ajay
[PHP] Re: How to "download" a multi-part file at the "server" side?
I just came across http://www.w3schools.com/php/php_file_upload.asp, and tested it.. It works fine, when the file is uploaded via a form. It does seem that the client-method might indeed play a role. Here is my Java code for uploading the file :: ### HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost(URL); File file = new File("/path/to/png/file.png"); // Send the image-file data as a Multipart-data. MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/png"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); HttpResponse response = httpclient.execute(httppost); ### Any ideas if making a change at the client (Java) OR/AND server (PHP) might do the trick? On Sat, Nov 2, 2013 at 6:06 PM, Ajay Garg wrote: > Hi all. > > I intend to implement a use-case, wherein the client uploads a file in > multi-part format, and the server then stores the file in a mysql database > (after "downloading it at the server side). > > I have been unable to find any immediate answers through googling; I will > be grateful if someone could start me in a direction to achieve the > "downloading at server via php" requirement. > > (Don't think it should matter, but I use Java to upload a file in > multi-part format). > > I will be grateful for some pointers. > > Thanks in advance > > > Thanks and Regards, > Ajay > -- Regards, Ajay
Re: [PHP] How to "download" a multi-part file at the "server" side?
Hi Aziz. Thanks for the reply. Unfortunately, making the change suggested by you does not make any difference :( Sorry, Thanks and Regards On Sat, Nov 2, 2013 at 10:51 PM, Aziz Saleh wrote: > > > > On Sat, Nov 2, 2013 at 1:03 PM, Ajay Garg wrote: > >> Hi all. >> >> 1. >> I could have the proper "$_FILES["userfile"]["name"]" been echoed back, by >> replacing >>ContentBody cbFile = new >> FileBody(file, "image/png"); >> >> with >>ContentBody cbFile = new >> FileBody(file); >> >> >> >> 2. >> However, now I am stuck with the following server-side code. >> No matter what I do, I always get a "no" echoed back (specifying that the >> file is not copied to its target place). >> >> >> >> >> ### >> > >> $headers = apache_request_headers(); >> >> foreach ($headers as $header => $value) >> { >> if($header == "active_window_title") >> { >> $active_window_title = $value; >> break; >> } >> } >> >> >> $target_path = "/home/ajay/success.png"; >> >> move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_path); >> if(file_exists($target_path)) >> { >> echo "yes"; >> } >> else >> { >> echo "no"; >> } >> >> echo "\n" . $_FILES["userfile"]["name"]; # I always get the proper >> file-name echoed. >> >> ?> >> >> >> >> >> >> >> >> Any ideas what stupidity am I making in the PHP code? >> >> >> On Sat, Nov 2, 2013 at 7:13 PM, Ajay Garg wrote: >> >> > Does not work :( >> > >> > >> > As per the code-snippet I pasted, >> > $_FILES["userfile"]["name"] >> > >> > should be >> > >> /path/to/png/file.png >> > >> > >> > However, $_FILES["userfile"]["name"] is empty. >> > >> > >> > On Sat, Nov 2, 2013 at 6:59 PM, Shawn McKenzie > >wrote: >> > >> >> Fairly easy: >> >> http://www.php.net/manual/en/features.file-upload.post-method.php >> >> >> >> >> >> On Sat, Nov 2, 2013 at 7:36 AM, Ajay Garg >> wrote: >> >> >> >>> Hi all. >> >>> >> >>> I intend to implement a use-case, wherein the client uploads a file in >> >>> multi-part format, and the server then stores the file in a mysql >> >>> database >> >>> (after "downloading it at the server side). >> >>> >> >>> I have been unable to find any immediate answers through googling; I >> will >> >>> be grateful if someone could start me in a direction to achieve the >> >>> "downloading at server via php" requirement. >> >>> >> >>> (Don't think it should matter, but I use Java to upload a file in >> >>> multi-part format). >> >>> >> >>> I will be grateful for some pointers. >> >>> >> >>> Thanks in advance >> >>> >> >>> >> >>> Thanks and Regards, >> >>> Ajay >> >>> >> >> >> >> >> > >> > >> > -- >> > Regards, >> > Ajay >> > >> >> >> >> -- >> Regards, >> Ajay >> > > Ajay, try changing your mpEntity to: > > new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE) > > See if it makes a difference. > Ajay