你可以使用一個服務器端語言,並存儲信息/控制訪問的方式。你不需要在那個方向上使用.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