How to Move an uploaded file in PHP

02nd, January 2018 By

The move_uploaded_function() are used to move the uploaded file to any location.This function can return true on success and false on failure.

This function have two parameter files name and second one the destination of the file.

 move_uploaded_file ( $filename , $destination )

Where $filename = Name of the file moving
$destination = The destination of the moved file.

You can change the example function as your requirement and path of the upload folder on server.

Example:-


<?php
// Example of move the file uploaded
$fileName = $_FILES["upload_file"]["name"];
$fileTL = $_FILES["upload_file"]["tmp_name"];
// Path and file name
$path = "uploads/".$fileName;

$Result = move_uploaded_file($fileTL, $path);
// Return if needed
if ($Result == true) {
    echo "File has been moved;
} else {
     echo "ERROR: File movement not working";
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *