小编use*_*125的帖子

如何使用php标题从特定目录下载文件

我有一些代码使用PHP标题下载文件,但它没有正常工作,并希望添加目录阅读

    <?php
if(isset($_GET['link'])){
    $var_1 = $_GET['link'];
$dir='/upload/';
}
?>
<?php
if(isset($_GET['link'])){
    $var_1 = $_GET['link'];
$file = $var_1;
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
echo "<h1>Content error</h1><p>The file does not exist!</p>";
}
?>
Run Code Online (Sandbox Code Playgroud)

它显示错误内容错误

该文件不存在!

我在用

http://sap.layyah.info/download.php?link=UAC.dll

这个链接下载文件原始位置是

http://sap.layyah.info/upload/UAC.dll

php header

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

header ×1

php ×1