【问题标题】:Is there a way to disallow direct access of file but allow download via PHP script using IIS?有没有办法禁止直接访问文件但允许使用 IIS 通过 PHP 脚本下载?
【发布时间】:2014-11-21 17:20:41
【问题描述】:

我目前有一个提供下载的 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. 
}

【问题讨论】:

  • 您是否尝试过将文件移出公用文件夹?这样就不会有公开的下载链接
  • 我试过了,但没有运气。这些文件将立即下载并为空。
  • 如果它在公用文件夹之外,您应该无法获得该文件的链接。
  • 我说的是下载脚本。下载脚本能否访问公用文件夹之外的内容?
  • 是的,许多 MVC 框架都在公用文件夹之外。但是,更多地研究 IIS 看起来并不像它允许的那样。这可能会有所帮助:stackoverflow.com/questions/270284/…

标签: php iis


【解决方案1】:

我能够按照这些说明进行操作

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

【讨论】:

    猜你喜欢
    • 2011-02-10
    • 2022-11-28
    • 2023-03-18
    • 1970-01-01
    • 2016-02-22
    • 2014-04-02
    • 2017-03-04
    • 2016-10-24
    • 2017-08-06
    相关资源
    最近更新 更多