PHP move_uploaded_file() Function Guide
The move_uploaded_file function is used to move uploaded files to a specified destination folder. Its syntax is as follows:
move_uploaded_file ( string $filename , string $destination ) : bool
The function will return a boolean value indicating whether the moving process was successful, with $filename representing the temporary path of the uploaded file, and $destination representing the path of the target folder.
Here is an example code:
$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name'];
if (move_uploaded_file($uploadedFile, $destination)) {
echo '文件移动成功';
} else {
echo '文件移动失败';
}
In the example above, $_FILES[‘file’][‘tmp_name’] represents the temporary path of the uploaded file, while ‘uploads/’ . $_FILES[‘file’][‘name’] represents the path of the destination folder. If the file is moved successfully, it will output “File moved successfully”, otherwise it will output “File moved failed”.