PHP:提供下载文件而不提供直接链接

前端之家收集整理的这篇文章主要介绍了PHP:提供下载文件而不提供直接链接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想提供下载发票.目前我使用的是简单的编号方案(invoice-01.pdf,invoice-02.pdf等).我知道我可以使用哈希来掩盖数据.

是否也可以使用PHP并通过不直接让用户指向它们来提供发票?

php.net甚至有一个例子 @H_301_7@<?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'); ?>

或者扩展一下

@H_301_7@<?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"); } ?>

猜你在找的PHP相关文章