How can one ensure that uploaded files are saved in the correct directory in PHP?

When uploading files in PHP, it is important to specify the correct directory where the files should be saved to ensure they are stored in the desired location. This can be achieved by setting the destination directory path in the move_uploaded_file function when handling file uploads. By specifying the correct directory path, you can ensure that the uploaded files are saved in the intended location.

// Specify the destination directory where the uploaded files should be saved
$uploadDirectory = 'uploads/';

// Move the uploaded file to the specified directory
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadDirectory . $_FILES['file']['name'])) {
    echo 'File uploaded successfully!';
} else {
    echo 'File upload failed.';
}