我将文件存储在服务器的根目录之上,并计划使用php文件为用户提供下载。
这是我的代码:下载链接:
<a href="'.FILEGRAB_ADR.'?adr='.$file.'">Download</a>
对于FileGrab.php文件:
<?php
//This will grab a file from the server
if (file_exists(UPLOAD_ADR.$_GET['adr'])) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.CATPart"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header("Content-length: ".filesize(UPLOAD_ADR.$_GET['adr']));
readfile(UPLOAD_ADR.$_GET['adr']);
exit;
}
?>
我从这里得到了上面的代码(本质上)
FileGrab.php正在加载,但它看起来只是喷出文件的原始文本形式、任意文本/符号等。
已检查文件是否存在,并且文件大小返回一个值。不知道如何获得更多的错误来检查它!
这是一个.CATPart文件,它有点抽象,但很必要。。。
非常感谢您的帮助:)
尝试通过在ob_start()和ob_end_flush();之间包围代码来使用缓冲函数。当然,在发送标头之前,请确保没有使用空格或回声。
有关更多信息,请查看以下链接:
http://php.net/manual/en/ref.outcontrol.php
为什么在PHP中使用输出缓冲?