What precautions should be taken when including files from the filesystem in PHP?

When including files from the filesystem in PHP, it is important to sanitize user input to prevent directory traversal attacks. One way to do this is by using the `realpath()` function to get the absolute path of the file being included. Additionally, it is recommended to store files in a directory outside of the web root to prevent direct access to sensitive files.

$filename = realpath('/path/to/your/files/' . $_GET['file']);

if ($filename !== false && strpos($filename, '/path/to/your/files/') === 0) {
    include $filename;
} else {
    echo 'Invalid file path';
}