What are the common file permission issues that can lead to "Permission denied" errors when trying to open a file in PHP?

Common file permission issues that can lead to "Permission denied" errors in PHP include insufficient permissions for the file or directory, incorrect ownership of the file, or the file being locked by another process. To solve this issue, you can check and adjust the file permissions using the chmod() function in PHP.

// Check and adjust file permissions
$filename = 'example.txt';
if (!is_readable($filename)) {
    chmod($filename, 0644); // Set file permissions to allow reading
}

// Open the file
$file = fopen($filename, 'r');
if ($file) {
    // File opened successfully
    fclose($file);
} else {
    // Error opening file
    echo 'Permission denied';
}