从绝对路径下载文件

Download file from 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 );

应该是

readfile($fileurl)

您确定该文件存在并且服务器对该文件具有正确的访问权限吗? Content-Length header 呢?

您只需要更改一行。

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