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
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to be moved |
newloc | Required. | 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");
}
}
?>