How can the PHP function fopen be utilized to check for file existence and handle URL file-access limitations?

When using the PHP function fopen to check for file existence and handle URL file-access limitations, you can use the 'file_exists' function to check if the file exists before attempting to open it with fopen. Additionally, you can use the 'ini_set' function to enable or disable URL file-access restrictions based on your requirements.

$file = 'example.txt';

if (file_exists($file)) {
    $handle = fopen($file, 'r');
    // Handle file operations here
    fclose($handle);
} else {
    echo 'File does not exist.';
}

// Enable or disable URL file-access restrictions
ini_set('allow_url_fopen', 1); // Enable
// ini_set('allow_url_fopen', 0); // Disable