move_uploaded_file() function in PHP


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements