What are the potential security risks of using PHP to browse files on a client's computer?

Using PHP to browse files on a client's computer can pose security risks such as exposing sensitive information, allowing unauthorized access to files, and potentially executing malicious code. To mitigate these risks, it is important to validate user input, sanitize file paths, and restrict access to only necessary directories.

<?php
$directory = '/path/to/allowed/directory/';
$filename = $_GET['file'];

if (strpos(realpath($filename), $directory) === 0) {
    // Proceed with file browsing
} else {
    // Display error message or redirect
    echo 'Access denied';
}
?>