[PHP] Re: file upload question
seb wrote: Hey all, i am using move_upload function to upload files to the server, but i want to add a feature that will allow files to be archived that have been uploaded already. so, the problem is: i upload a file that i want to upgrade and move the old file to an archive directory but I want to verify the NEW file is upload BEFORE moving the old file (the file being uploaded might not have the same filename as the old file currently on the server).. i want to move the old file only when the new file was successfully uploaded. something like: if(move_uploaded_file()) { rename(...); } only one problem.. then if both files have the same name it will be overwritten before it moves the old one i want to save. if i move the old one first, there still the possibility of the new upload failing so i am back to square one.. i guess i can move_upload to a different directory, verify it's been uploaded, move the old to the archive file, then move the new file back to where it should be (where the archive file was).. is that my only option? any suggestions? I'd suggest you *copy* the old file (if it exists) to archive anyway, and then *move* it back if the new version doesn't verify. That seems pretty safe to me... -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: file upload question
i add me to the question. 2009/8/3 Peter Ford p...@justcroft.com seb wrote: Hey all, i am using move_upload function to upload files to the server, but i want to add a feature that will allow files to be archived that have been uploaded already. so, the problem is: i upload a file that i want to upgrade and move the old file to an archive directory but I want to verify the NEW file is upload BEFORE moving the old file (the file being uploaded might not have the same filename as the old file currently on the server).. i want to move the old file only when the new file was successfully uploaded. something like: if(move_uploaded_file()) { rename(...); } only one problem.. then if both files have the same name it will be overwritten before it moves the old one i want to save. if i move the old one first, there still the possibility of the new upload failing so i am back to square one.. i guess i can move_upload to a different directory, verify it's been uploaded, move the old to the archive file, then move the new file back to where it should be (where the archive file was).. is that my only option? any suggestions? I'd suggest you *copy* the old file (if it exists) to archive anyway, and then *move* it back if the new version doesn't verify. That seems pretty safe to me... -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: File Upload Question
As far as I know, this is not possible. You can however generate more file-upload boxes dynamicly. In this way, users can click an 'Upload another file'-button to display an extra upload form-element. Check the 'variable variables'-part in the PHP reference (user notes) for an example of this construction. Hope this is good solution for your application. greetz, Arnout Boks Warren Vail [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] Perhaps this is more about HTML than PHP, but the PHP $_FILES var seems to be set up to allow a list of files to be uploaded. How does one get the pop-up window to allow a user to select (ctrl-click or whatever) multiple files in the same pop-up window? Everything I have tried has left the user restricted to selecting one file only. thanks in advance. Warren Vail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: File Upload Question...
Your first question. To see that the file uploaded successfully using the web browser, one would have to have access to your computer's file system. In her book, she used this merely as an example to show that the file had, indeed, been uploaded. This should not be used as something that you allow your web users to do to confirm the receipt of the file. Instead, send them an email, show them a directory listing, etc. Your second question, the name given to the image should be whatever the *value* of the variable used to copy() it. You should, however, come up with a naming scheme that allows you to ensure that you do not overwrite any uploaded files--especially if you expect a lot of traffic and/or users using this feature. Your third question, the mime-type pjpg is functionally the same as the mime-type jpeg. There's nothing you need to worry about there. Anthony Ritter [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Merry Christmas everybody. I am using MS Windows 98 with Apache and following an example in Julie Meloni's PHP - Fast and Easy (Chapter 10) in which she describes file uploading using PHP on page 168-174. She has two files: 1) an html form to receive the input from the user for the file to be uploaded 2) a .php script to accept the variable and use the copy() function. . The scripts are as follows: (html form) HTML HEAD TITLEUpload a File/TITLE /HEAD BODY H1Upload a File/H1 FORM METHOD=post ACTION=do_upload.php ENCTYPE=multipart/form-data pstrongFile to Upload:/strongbr INPUT TYPE=file NAME=img1 SIZE=30/p PINPUT TYPE=submit NAME=submit VALUE=Upload File/p /FORM /BODY /HTML (.php script) ? if ($img1_name != ) { @copy($img1, c:/Program Files/Apache Group/Apache/htdocs/$img1_name) or die(Couldn't copy the file.); } else { die(No input file specified); } ? HTML HEAD TITLESuccessful File Upload/TITLE /HEAD BODY H1Success!/H1 PYou sent: ? echo $img1_name; ?, a ? echo $img1_size; ? byte file with a mime type of ? echo $img1_type; ?./P /BODY /HTML .. My questions: I am able to upload a file from My Documents to the Apache server however in her book, she describes that the user can verify that the file was uploaded to the server by going to: File/ Open Page / in ones web browser to navigate through their filesystem to find the file that was uploaded. There is a screenshot in the book that shows the .jpeg file on the screen with the browser at: file:///C/Apache/htdocs/blahblah.jpg I can't seem to verify that the file exists using this method. The only way I can verify that the file was indeed uploaded is to go into the folder within Apache that was specified in the path and check there. *How can I check by going through the browser window?* Next question: When I check that the file was uploaded, the file is saved in: C:/Program Files/Apache Group/Apache/htdocs/$img1_name as the *regular *.jpeg name I originally gave it - not the variable - $img1. Is this correct? Or, should the file be saved as: img1? And the last question: This is the line I received upon sending the file: You sent: KewpieSmall.jpeg, a 3127 byte file with a mime type of image/pjpeg. In her book, it says: image/jpeg. What is: image/pjpeg.? Many thanks and best wishes to all for a happy and healthy new year. Tony Ritter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: File Upload Question...
Hi, Remember 2nd Q: The file is Upload to a temporaly direcory, later you copy from temporaly (temporaly name) to a final (rename the file) destination. Under *NIX, I don't if Windows's PHP when upload tthe file, the file is copied to a temporaly directory. Bye, I've still My Question about PHP_AUTH_USER and Browsers :-) Marry Chistmas... At 12:33 PM -0500 27/12/01, Jeremy Reed wrote: Your first question. To see that the file uploaded successfully using the web browser, one would have to have access to your computer's file system. In her book, she used this merely as an example to show that the file had, indeed, been uploaded. This should not be used as something that you allow your web users to do to confirm the receipt of the file. Instead, send them an email, show them a directory listing, etc. Your second question, the name given to the image should be whatever the *value* of the variable used to copy() it. You should, however, come up with a naming scheme that allows you to ensure that you do not overwrite any uploaded files--especially if you expect a lot of traffic and/or users using this feature. Your third question, the mime-type pjpg is functionally the same as the mime-type jpeg. There's nothing you need to worry about there. Anthony Ritter [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Merry Christmas everybody. I am using MS Windows 98 with Apache and following an example in Julie Meloni's PHP - Fast and Easy (Chapter 10) in which she describes file uploading using PHP on page 168-174. She has two files: 1) an html form to receive the input from the user for the file to be uploaded 2) a .php script to accept the variable and use the copy() function. . The scripts are as follows: (html form) HTML HEAD TITLEUpload a File/TITLE /HEAD BODY H1Upload a File/H1 FORM METHOD=post ACTION=do_upload.php ENCTYPE=multipart/form-data pstrongFile to Upload:/strongbr INPUT TYPE=file NAME=img1 SIZE=30/p PINPUT TYPE=submit NAME=submit VALUE=Upload File/p /FORM /BODY /HTML (.php script) ? if ($img1_name != ) { @copy($img1, c:/Program Files/Apache Group/Apache/htdocs/$img1_name) or die(Couldn't copy the file.); } else { die(No input file specified); } ? HTML HEAD TITLESuccessful File Upload/TITLE /HEAD BODY H1Success!/H1 PYou sent: ? echo $img1_name; ?, a ? echo $img1_size; ? byte file with a mime type of ? echo $img1_type; ?./P /BODY /HTML .. My questions: I am able to upload a file from My Documents to the Apache server however in her book, she describes that the user can verify that the file was uploaded to the server by going to: File/ Open Page / in ones web browser to navigate through their filesystem to find the file that was uploaded. There is a screenshot in the book that shows the .jpeg file on the screen with the browser at: file:///C/Apache/htdocs/blahblah.jpg I can't seem to verify that the file exists using this method. The only way I can verify that the file was indeed uploaded is to go into the folder within Apache that was specified in the path and check there. *How can I check by going through the browser window?* Next question: When I check that the file was uploaded, the file is saved in: C:/Program Files/Apache Group/Apache/htdocs/$img1_name as the *regular *.jpeg name I originally gave it - not the variable - $img1. Is this correct? Or, should the file be saved as: img1? And the last question: This is the line I received upon sending the file: You sent: KewpieSmall.jpeg, a 3127 byte file with a mime type of image/pjpeg. In her book, it says: image/jpeg. What is: image/pjpeg.? Many thanks and best wishes to all for a happy and healthy new year. Tony Ritter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- __ Jesus Maria Bianco Troconis (yisu) E-MAIL mailto:[EMAIL PROTECTED] ICQ4792036 / nickname yisu WEBhttp://yisu.net Telefono/Phone +58 (414) 3042346 (Ciudad/City) Caracas, Venezuela Mac, PHP MySQL Rulez. They Kick some ass! __ _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]