你可以使用一个服务器端语言,并存储信息/控制访问的方式。你不需要在那个方向上使用.htaccess。
安全来说,这是最好的方法,在我看来,因为您验证在后端的一切。
更新代码:
<?php
# Wrap this in your credentials -- #
$directory_path = $_SERVER['DOCUMENT_ROOT'] . "/directory/path/here/";
$file_path = $directory_path . $_GET['downloadfile'];
if ($file_exists = fopen ($file_path, "r"))
{
$file_size = filesize($file_path);
$file_parts = pathinfo($file_path);
$file_extenion = strtolower($file_parts["extension"]);
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$file_parts["basename"]."\"");
header("Content-length: $file_size");
header("Cache-control: private"); //use this to open files directly
while(!feof($file_exists))
{
$buffer = fread($file_exists, 2048);
echo $buffer;
}
}
fclose ($file_exists);
exit;
# -- End credential wrap -- #
?>
然后,你可以调用与download.php?downloadfile=something.jpg
文件你必须把相应的头/ MIME类型的文件和包裹在你的凭证验证,但这应该适用于亚。
如果您有任何疑问,请告知我。
来源
2011-02-22 16:36:25
TNC
你要问自己,为什么你会想保护他们用一个密码,如果他们都公开。 你当然有另一个想法背后,你能解释它吗? – Capsule 2011-02-22 16:40:02
[摘要式认证](http://en.wikipedia.org/wiki/Digest_access_authentication)没问题。如果全部都是通过HTTPS完成的,那么即使是基本身份验证也是安全的。 – DanMan 2011-02-22 18:16:53