PHP move_uploaded_file() Function

Definition

The move_uploaded_file() function moves an uploaded file to a new location.

Syntax

PHP move_uploaded_file() Function has the following syntax.

move_uploaded_file(file,newloc)

Parameter

ParameterIs RequiredDescription
fileRequired.File to be moved
newlocRequired.New location for the file

Return

This function returns TRUE on success, or FALSE on failure.

Note

This function only works on files uploaded via HTTP POST. If the destination file already exists, it will be overwritten.

Example

Moves an uploaded file to a new location


<?php/*from  www  . j  av  a  2  s  . co  m*/
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions