How can a file uploaded with $_FILES be moved in PHP?
To move a file uploaded with $_FILES in PHP, you can use the move_uploaded_file() function. This function takes two parameters: the temporary file location of the uploaded file and the destination where you want to move the file to. By using move_uploaded_file(), you can securely move the uploaded file to a specified directory on the server.
$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name'];
if (move_uploaded_file($uploadedFile, $destination)) {
echo 'File moved successfully.';
} else {
echo 'Failed to move file.';
}
Keywords
Related Questions
- Are there best practices for optimizing memory usage when working with image processing functions in PHP?
- What is the function that can be used in PHP to replace characters in a string?
- What best practices were recommended for structuring the database tables and PHP code to handle hotel room bookings effectively?