PHP move_uploaded_file() Function
In this chapter you will learn:
- Definition for PHP move_uploaded_file() Function
- Syntax for PHP move_uploaded_file() Function
- Parameter for PHP move_uploaded_file() Function
- Return for PHP move_uploaded_file() Function
- Note on PHP move_uploaded_file() Function
- Example - moves an uploaded file to a new location
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 ja va2s.c o 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");
}
}
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP opendir() Function
- Syntax for PHP opendir() Function
- Parameter for PHP opendir() Function
- Return for PHP opendir() Function
- Example - Open a directory, read its contents, then close
Home » PHP Tutorial » PHP File Functions