Page 1 of 1

copy() vs move_upload file()

Posted: Tue Oct 29, 2002 3:40 pm
by cooler75
hi,
just want to find out when to use copy() and when to use move_uploaded_file() when uploading files to the server.
how about is_uploaded_file() ?

thanks

Posted: Wed Oct 30, 2002 2:17 am
by twigletmac
Have a look at the docs:
copy() -
Makes a copy of a file. Returns TRUE if the copy succeeded, FALSE otherwise.
move_uploaded_file() -
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.
So if you're uploading files to the server using PHP's HTTP POST upload mechanism use move_uploaded_files(), if you're not and need to copy a file use copy().

http://www.php.net/manual/en/features.file-upload.php

move_uploaded_files() means instead of doing this:

Code: Select all

if (is_uploaded_file($_FILESї'userfile']ї'tmp_name'])) {
    copy($_FILESї'userfile']ї'tmp_name'], "/place/to/put/uploaded/file");
}
you can just do this:

Code: Select all

move_uploaded_file($_FILESї'userfile']ї'tmp_name'], "/place/to/put/uploaded/file");
Mac