How can the PHP code be modified to specify the destination directory for file uploads to prevent the "Permission denied" error?
To specify the destination directory for file uploads in PHP and prevent the "Permission denied" error, you need to ensure that the destination directory has the correct permissions set for the web server to write to it. You can do this by changing the permissions of the directory using chmod or chown commands. Additionally, you can specify the destination directory in the move_uploaded_file function when moving the uploaded file.
<?php
$uploadDirectory = '/path/to/destination/directory/';
$uploadedFile = $_FILES['file']['tmp_name'];
$destinationFile = $uploadDirectory . $_FILES['file']['name'];
if(move_uploaded_file($uploadedFile, $destinationFile)) {
echo "File uploaded successfully.";
} else {
echo "Error uploading file.";
}
?>