The php Function MoveUploadedFile
The php function move_uploaded_file moves an uploaded file to a new destination. It also checks to make sure that the file designated by filename is a valid upload file (meaning it has been uploaded via PHP's HTTP POST upload mechanism). If the file is not a valid upload file, then it will not be moved and move_uploaded_file() will return false. 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.
This function works only on a file submitted via HTTP POST, and does not work on any other file in your system. You must have the container folder where you want to move the uploaded file already created.
If the target folder does not exist, or if you pass an invalid path to move_uploaded_file() then an error will be thrown. This is because the PHP script that created the container folder may not have owned the file, or it may have been uploaded by another user.
This is why it's always a good idea to encode files that are uploaded by users, so they are not easily read by other people who might access the same file in your system. For example, use enctype='multipart/form-data' when accepting file submissions from your web forms. This will prevent php from reading the uploaded file in plain text, and potentially revealing sensitive information.