move_uploaded_file() function in PHP

PHPProgrammingServer Side Programming

The move_uploaded_file() function moves an uploaded file to a new location. If the destination file already exists, it will be overwritten.

Syntax

move_uploaded_file(file_path, moved_path)

Parameters

  • file_path − The file to be moved.

  • moved_path − Where the file will be moved.

Return

The move_uploaded_file() function returns true on success and false on failure.

Example

 Live Demo

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

Output

Upload failed!PHP Notice: Undefined index: userfile in /home/cg/root/8944881/main.php on line 2
raja
Published on 04-Oct-2018 08:24:24
Advertisements