How to use PHP move_uploaded_file to move uploaded file

PHP move_uploaded_file

The move_uploaded_file() function is used to move uploaded file to the specified location.

The move_uploaded_file() function returns true if the move is successful and false if it fails.

The PHP move_uploaded_file will overwrite if the file already exists with the same name.

For illustration, how to use move_uploaded_file() function see an example below.

Example of using move_uploaded_file

The following example is a script for PHP file uploading that uses the move_uploaded_file function to move a file to the specified location in server.

For making it clearer, both HTML (client side) and PHP script are given below in two steps:

Step 1 – User interface

Step 1 is just the HTML file to select a file from the system or device.

Step 2- Using PHP move_uploaded_file function

This step uses the move_uploaded_file function as below:

For more on PHP file uploading, read its complete chapter here: PHP file upload.