有没有一种方法可以禁止直接访问文件,但允许使用IIS通过PHP脚本下载


Is there a way to disallow direct access of file but allow download via PHP script using IIS?

我目前有一个php脚本,提供下载服务,您可以在下面查看。它工作得很好,但我想要它,所以即使你有一个文件的直接链接,你也不能用它来下载它。我目前正在使用IIS 7。我看到有请求过滤,但我不知道如何在不完全阻止访问文件的情况下使用它。

$extension = fileexten($filename);
if(($filename!= false)&&($fakename!=false&& @fopen($filename,'r')==true)){
$mime = contenttype($extension);
set_time_limit(0);
header('Pragma: public');
header('Expires: 0'); 
header("Content-Type:".$mime);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);        
header('Content-Disposition: attachment;filename='.$fakename.'.'.$extension);
header("Content-Transfer-Encoding: binary");
  if (ob_get_length() > 0) {
    ob_end_clean();
    }
flush();
readfile($filename);
}
else{
$error = "<h3>We could not find this file</h3>";} // If the filename or fake filename could not be retrieved. 
}

我能够按照的指示进行操作

https://stackoverflow.com/a/22575734/104253