How does the move_uploaded_file() function in PHP handle file transfer errors and what are common causes of failure?
When using the move_uploaded_file() function in PHP, it is important to handle potential errors that may occur during the file transfer process. Common causes of failure include insufficient permissions, exceeding file size limits, and invalid file paths. To handle errors, you can use conditional statements to check for errors and provide appropriate error messages or logging.
$uploadDir = 'uploads/';
$uploadFile = $uploadDir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
echo "File uploaded successfully.";
} else {
echo "Error uploading file.";
}