从绝对路径下载文件

时间:2016-08-03 12:40:25

标签: php header readfile absolute-path

我正在尝试从绝对路径下载文件,但我无法让它工作。我做错了什么?

$fileurl = '/home/mydomain/public_html/wp-content/uploads/312tekstsecure3.pdf';
header("Content-type:application/pdf");
header('Content-Disposition: attachment; filename=' . $fileurl);
readfile( $fileurl );

3 个答案:

答案 0 :(得分:3)

您只需更改一行。

<?php 
$fileurl = 'yourpath/file.pdf';
header("Content-type:application/pdf");
header('Content-Disposition: attachment; filename=' . $fileurl);
readfile( $fileurl );
?>

答案 1 :(得分:0)

应该是

readfile($fileurl)

答案 2 :(得分:0)

您确定文件存在且服务器对此文件具有正确的访问权限吗?那么Content-Length标题呢?

相关问题