我们有一些 PDF 文件,我们希望它通过 php 呈现,而不是直接提供文件链接,以便只有经过身份验证的用户才能下载 pdf 文件。因此我们不需要向用户提供文件路径。
是否可以?
曼格什
您可以,这是一个示例:
<?php
$file = './path/to/the.pdf';
$filename = 'You dont know where I am.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2615 次 |
最近记录: |