The move_uploaded_file() function moves an uploaded file to a new location.
PHP move_uploaded_file() Function has the following syntax.
move_uploaded_file(file,newloc)
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to be moved |
newloc | Required. | New location for the file |
This function returns TRUE on success, or FALSE on failure.
This function only works on files uploaded via HTTP POST. If the destination file already exists, it will be overwritten.
Moves an uploaded file to a new location
<?php/*from w ww.j ava 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");
}
}
?>