PHP move_uploaded_file
时间: 2023-10-23 13:12:13 浏览: 107
move_uploaded_file is a PHP function that is used to move an uploaded file to a new location. This function is typically used in conjunction with the $_FILES superglobal variable, which contains information about the uploaded file.
The syntax for move_uploaded_file is as follows:
move_uploaded_file($filename, $destination);
The first parameter, $filename, is the name of the file that was uploaded. The second parameter, $destination, is the new location where the file should be moved.
Here is an example of how to use move_uploaded_file in a PHP script:
<?php
if(isset($_FILES['file'])){
$filename = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$destination = "uploads/" . $filename;
move_uploaded_file($tmp_name, $destination);
echo "File uploaded successfully";
}
?>
In this example, the script checks if a file has been uploaded using the $_FILES superglobal variable. If a file has been uploaded, it gets the name and temporary location of the file from the $_FILES variable. It then sets the destination folder for the uploaded file and uses the move_uploaded_file function to move the file from its temporary location to the destination folder. Finally, the script outputs a message to let the user know that the file has been uploaded successfully.
阅读全文