What are the limitations of accessing the local file system from a web server in PHP?

Accessing the local file system from a web server in PHP can pose security risks, as it may expose sensitive files or allow for malicious file operations. To mitigate this, it is recommended to limit access to only specific directories and files that are necessary for the application to function properly. Additionally, using proper file permissions and sanitizing user input can help prevent unauthorized access or malicious file operations.

// Example of limiting access to a specific directory
$allowed_directory = '/var/www/html/uploads/';
$user_requested_file = $_GET['file'];

if (strpos(realpath($user_requested_file), $allowed_directory) !== 0) {
    die('Access denied');
}

// Proceed with file operations