robert_gsfame Posted July 15, 2010 Share Posted July 15, 2010 I just want the different between copy() VS move_uploaded_file when it comes to upload file. I always use copy not move_uploaded_file...what is the difference and which is the best to be used?? thx Quote Link to comment https://forums.phpfreaks.com/topic/207813-copy-vs-move_uploaded_file/ Share on other sites More sharing options...
bh Posted July 15, 2010 Share Posted July 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/207813-copy-vs-move_uploaded_file/#findComment-1086332 Share on other sites More sharing options...
robert_gsfame Posted July 15, 2010 Author Share Posted July 15, 2010 If the file is valid, it will be moved to the filename given by destination?? in what case the file is not valid?? size, filetype?? but we validate the file before move it into certain folder...so in what case the file is not valid?? thx Quote Link to comment https://forums.phpfreaks.com/topic/207813-copy-vs-move_uploaded_file/#findComment-1086337 Share on other sites More sharing options...
bh Posted July 15, 2010 Share Posted July 15, 2010 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... http://php.net/manual/en/function.move-uploaded-file.php Quote Link to comment https://forums.phpfreaks.com/topic/207813-copy-vs-move_uploaded_file/#findComment-1086339 Share on other sites More sharing options...
robert_gsfame Posted July 15, 2010 Author Share Posted July 15, 2010 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...?? Quote Link to comment https://forums.phpfreaks.com/topic/207813-copy-vs-move_uploaded_file/#findComment-1086340 Share on other sites More sharing options...
bh Posted July 15, 2010 Share Posted July 15, 2010 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. http://php.net/manual/en/function.copy.php And you can check the copy was whether successed example with http://php.net/manual/en/function.file-exists.php Quote Link to comment https://forums.phpfreaks.com/topic/207813-copy-vs-move_uploaded_file/#findComment-1086344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.