서버 측 언어를 사용하여 정보/제어 액세스를 그런 식으로 저장할 수 있습니다. 그 방향으로 .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 -- #
?>
이 그런 다음 당신은 적절한 헤더 파일에 대한/MIME 유형을 넣어해야합니다 download.php?downloadfile=something.jpg
로 파일을 호출하고 자격 증명에 그 포장 수 validatation,하지만 그건 나중에 작동합니다.
궁금한 점이 있으면 알려주세요.
출처
2011-02-22 16:36:25
TNC
공개적으로 사용할 수있는 경우 암호로 보호하고 싶은 이유가 무엇인지 스스로 자문해야합니다. 확실한 이유가 무엇입니까? 설명해 주시겠습니까? – Capsule
[다이제스트 인증] (http://en.wikipedia.org/wiki/Digest_access_authentication) 괜찮습니다. 모든 것이 HTTPS를 통해 이루어지면 기본 인증조차도 보안 상 좋습니다. – DanMan