What are the recommended approaches for troubleshooting and debugging PHP scripts that encounter issues with file uploads?

When troubleshooting and debugging PHP scripts that encounter issues with file uploads, it is important to check the file upload settings in php.ini, ensure that the form has the correct enctype attribute set to "multipart/form-data", and verify that the destination directory has the correct permissions set for file uploads to be saved successfully.

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="fileToUpload">
    <input type="submit" value="Upload File" name="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $targetDir = "uploads/";
    $targetFile = $targetDir . basename($_FILES["fileToUpload"]["name"]);
    
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>