我想提供发票以供下载。目前我正在使用一个简单的编号方案(invoice-01.pdf、invoice-02.pdf 等)。我知道我可以使用哈希来代替数据。
是否也可以使用 PHP 并通过不直接让用户指向它们来提供发票?
Smu*_*dge 28
在php.net上甚至有这样的例子
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
Run Code Online (Sandbox Code Playgroud)
或者稍微扩展一下
<?php
if ( can_this_file_be_downloaded() ) {
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="invoice.pdf"');
readfile("{$_GET['filename']}.pdf");
} else {
die("None shall pass");
}
?>
Run Code Online (Sandbox Code Playgroud)
小智 5
山姆有答案。还将它们放在一个带有 .htaccess 的目录中:
Authname Private
AuthType basic
require user noadmittance
Run Code Online (Sandbox Code Playgroud)
如果他们知道 url,这将阻止直接访问。您仍然可以使用 readfile() 从 PHP 脚本中读取它。
| 归档时间: |
|
| 查看次数: |
47527 次 |
| 最近记录: |