假设您有一堆文档托管在您的网络服务器上,但您不希望通过直接 HTTP 请求检索它们,因为这些文件是机密文件。我们开始加密文件名,但我们希望它更进一步,那么将这些文件放在 /public_html 文件夹之外并让 PHP 从 /public_html 之外的文件夹中检索请求的文件呢?
我正在尝试对此进行测试,但我的小脚本正在检索我一个文件名错误的 0kb .pdf 文件:
<?php
$file = '/home/clientaccount/secretfiles/file.pdf';
if(!file_exists($file)){
die('Error: File not found.');
}
else
{
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
} ?>