使用某种代理 PHP 脚本,该脚本将为用户提供文件,而无需提供真实的源位置。
然后用户会看到http://yourdomain.com/download.php?file=mydoc.docx
真正的路径仍然是 /documents/userid/2342/mydoc.docx 或者你的结构是什么样的。
然后让您的 download.php 文件通过以下方式提供文件:
<?php
// Validate the user here
// Set document root
$root = 'documents/userid/'.$userID.'/';
// Requested file
$file = $_GET['file'];
// Validate
if (file_exists($root . $file))
{
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($root . $file));
ob_clean();
flush();
readfile($root . $file);
}
else { echo "File not found"; }
?>
在这里查看更多