Re: file upload question
| From: | Peter Ford | Date: | Mon, 03 Aug 2009 14:31:12 +0000 |
| Subject: | Re: file upload question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296200@lists.php.net to get a copy of this message | ||
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 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent