file upload question

file upload question

am 03.08.2009 13:04:29 von Seb

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?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: file upload question

am 03.08.2009 14:45:04 von Phpster

On Aug 3, 2009, at 7:04 AM, 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:
>
>
>
> 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?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Do an check for the file before moving it

If(file_exists($filename)){
// copy file out to archive
}

}if(move_uploaded_file(....))
{


}

Bastien






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: file upload question

am 03.08.2009 16:31:12 von Peter Ford

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: file upload question

am 03.08.2009 18:37:32 von Daniel Echalar

--00504502d29ef2cfef04703f62a8
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

i add me to the question.

2009/8/3 Peter Ford

> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--00504502d29ef2cfef04703f62a8--