Jump to content

copy() VS move_uploaded_file


robert_gsfame

Recommended Posts

From the php manual for the move_uploaded_file function:

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.

 

This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.

 

'valid uploaded file' = php runs the is_uploadedfile function within move_uploaded_file function. So mainly the move_uploaded_file is better when you want to move an uploaded file, cause security issues.

Again from php manuals:

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

 

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

 

So, please...  :rtfm:

http://php.net/manual/en/function.move-uploaded-file.php

Oops one more question, i got the error when checking whether file has been copy into the folder using copy()...i cant solve this problem yet, so i decided to use move_uploaded_file to avoid the error...

 

why cant i get the return value "TRUE" of "FALSE" use copy() so that the error appeared...it seems like copy() cannot read my filename...??

Anyway its away from the topic.

 

You can get wether the copy was success or failure:

From php manuls:

Returns TRUE on success or FALSE on failure.

 

:rtfm:http://php.net/manual/en/function.copy.php  :rtfm:

 

And you can check the copy was whether successed example with http://php.net/manual/en/function.file-exists.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.