<?php
$proxiedDirectory = "./files/"; //Whatever the directory you blocked access to is.
$filename = isset($_GET["fn"])?$_GET["fn"]:null;
if (!user_is_authenticated()) { //Not a real method, use your own check
http_response_code(403);
exit;
}
if ($filename === null || !file_exists($proxiedDirectory.$filename)) {
http_response_code(404);
exit;
}
$fp = fopen($proxiedDirectory.$filename, 'rb');
header("Content-Type: image/???"); //May need to determine mime type somehow
header("Content-Length: " . filesize($proxiedDirectory.$filename));
fpassthru($fp);
exit;
1条答案
按热度按时间b4lqfgs41#
您无法单独使用
.htaccess
来执行此操作。您需要执行以下操作:1.拒绝所有人访问文件
1.有一个“文件提供程序”脚本,允许在身份验证后通过文件。
示例:
代理服务器.php
您可以通过以下方式使用此功能:
http://example.com/proxy.php?fn=filename.txt