move file upload in php code example

Example 1: php move file

//Use the rename() function.
rename('first_location/image1.jpg', 'new_location/image1.jpg');

Example 2: move uploaded file in php

<?php
   if (move_uploaded_file($_FILES['userfile']['tmp_name'], "/documents/new/")) {
      print "Uploaded successfully!";
   } else {
      print "Upload failed!";
   }
?>

Example 3: php move_uploaded_file

$upload_folder = "upload/";
$file_location = $upload_folder . basename($_FILES["fileToUpload"]["name"]);

     if(isset($_FILES['fileToUpload'])){ 

        if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file_location)){
            
            echo 'Files has uploaded'; 
        };

     }

Example 4: php move uploaded file

move_uploaded_file ( string $filename , string $destination ) : bool

Tags:

Php Example