How can the issue of failed file opening be debugged effectively in PHP scripts?

Issue: Failed file opening in PHP scripts can be debugged effectively by checking if the file exists and if the necessary permissions are set correctly. Additionally, using error handling techniques such as try-catch blocks can help in identifying and handling any exceptions that may arise during the file opening process. PHP Code Snippet:

$file = 'example.txt';

if (file_exists($file) && is_readable($file)) {
    try {
        $handle = fopen($file, 'r');
        // File opening successful, continue with processing
    } catch (Exception $e) {
        echo 'Error opening file: ' . $e->getMessage();
    }
} else {
    echo 'File does not exist or is not readable.';
}