English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and Examples of PHP move_uploaded_file() Function

PHP Filesystem Reference Manual

The move_uploaded_file() function can move the uploaded file to a new location. If the filename is not a valid uploaded file, no operation can be performed and false is returned. If the filename is a valid uploaded file but cannot be moved for some reason, no operation is performed and false is returned. In addition, a warning can be issued.

Syntax

bool move_uploaded_file ( string $filename , string $destination )

 This function checks and ensures that the file specified by filename is a valid uploaded file (i.e., uploaded through PHP's HTTP POST upload mechanism). If the file is valid, it is moved to the file specified by destination.
This check is particularly important if there is a possibility that the uploaded file may cause the content to be displayed to the user or other users of this system.

Online Example

<?php
   $uploads_dir = "/PhpProject/uploads";
   foreach($_FILES["pictures"]["error"] as $key => $error) {
      if($error == UPLOAD_ERR_OK) {
         $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
         $name = basename($_FILES["pictures"]["name"][$key]);
         move_uploaded_file($tmp_name, "$uploads_dir/$name");
      }
   }
?>

PHP Filesystem Reference Manual