【发布时间】:2014-03-01 05:55:03
【问题描述】:
我们有一些 PDF 文件,而不是直接链接到文件,我们希望它通过 php 呈现,以便只有经过身份验证的用户才能下载 pdf 文件。因此我们不需要给用户文件路径。
有可能吗?
曼格什
【问题讨论】:
我们有一些 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);
?>
【讨论】: