当用户想从我的网站下载文件,用户必须点击如下图所示如何隐藏用户使用php的下载文件路径?
https://www.example.com/download.php?aaa=111&bbb=222
的download.php
<?PHP
session_start();
include("connect.php");
$aaa = mysql_real_escape_string($_GET[aaa]);
$bbb = mysql_real_escape_string($_GET[bbb]);
if(($aaa = '111')&($bbb = '222')) // this line is example for ask stackoverflow //
{
$filePath_try_to_download = 'attachments_files/test.pdf';
if(file_exists($filePath_try_to_download))
{
$fileSize = filesize($filePath_try_to_download);
$fileName = "test.pdf";
header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$fileName);
// Output file.
readfile ($filePath_try_to_download);
exit();
}
}
?>
我想知道从这个链接,当用户下载文件的链接https://www.example.com/download.php?aaa=111&bbb=222
用户可以在服务器上获取我的文件路径(attachments_files/test.pdf
)。如果用户可以得到我的文件路径,我怎么能隐藏它? (file in this dir is very importance
)
你使用什么服务器? Apache的?你不能用PHP来做你想做的事情,因为PHP只运行脚本 - 它不处理路由。 **还请注意,通过模糊处理的安全性根本就没有安全性。** –
@Matthew php可以轻松处理这个,而且没有任何模糊处理 –
@Hannky Panky-- pdf是示例 –