我正试图从一个绝对路径下载一个文件,但无法使其正常工作。我做错了什么?
$fileurl = '/home/mydomain/public_html/wp-content/uploads/312tekstsecure3.pdf';
header("Content-type:application/pdf");
header('Content-Disposition: attachment; filename=' . $fileurl);
readfile( $fileurl );
您只需要更改一行。
<?php
$fileurl = 'yourpath/file.pdf';
header("Content-type:application/pdf");
header('Content-Disposition: attachment; filename=' . $fileurl);
readfile( $fileurl );
?>
应该是
readfile($fileurl)
您确定该文件存在并且服务器对此文件具有正确的访问权限吗?Content-Length
标头如何?