What potential security issues can arise when using iFrames for file downloads in PHP?

Potential security issues that can arise when using iFrames for file downloads in PHP include the risk of exposing sensitive information, executing malicious scripts, and allowing unauthorized access to files on the server. To mitigate these risks, it is important to properly sanitize user input, validate file paths, and restrict access to files based on user permissions.

<?php
// Validate user input and restrict access to files based on permissions
$allowed_files = array(
    "file1.pdf" => "user1",
    "file2.pdf" => "user2"
);

if(isset($_GET['file']) && isset($allowed_files[$_GET['file']]) && $allowed_files[$_GET['file']] === $_SESSION['user']) {
    $file_path = 'path/to/files/' . $_GET['file'];
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
    readfile($file_path);
} else {
    echo "Unauthorized access";
}
?>