copy() vs move_upload file()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

copy() vs move_upload file()

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply