如何知道.htaccess受保护文件夹中的file_exist

时间:2014-07-18 08:19:51

标签: php .htaccess .htpasswd

如何通过.htaccess(我知道密码)密码保护文件夹中的文件如何找出

这不起作用:

$filename = "http://username:password@website.com/pictures/12.jpg"; // folder have password


if (file_exist($filename)) {

return TRUE;

} else return FALSE;

但是如果其他一些文件夹没有.htacces密码,那么这段代码很有用:

$ filename =“http://website.com/pictures_without_password/12.jpg”; //文件夹没有密码

if (file_exist($filename)) {

return TRUE;

} else return FALSE;

由于

1 个答案:

答案 0 :(得分:0)

file_exists HTTP以上$file = 'http://username:password@website.com/pictures/'; $file_headers = @get_headers($file); if($file_headers[0] == 'HTTP/1.1 404 Not Found') { $exists = false; } else { $exists = true; } 可能很好看,

请尝试以下方法:

function get_http_response_code($theURL) {
    $headers = get_headers($theURL);
    return substr($headers[0], 9, 3);
}

$file = 'http://username:password@website.com/pictures/';
if(get_http_response_code($file) == '404') {
    $exists = false;
} else {
    $exists = true;
}

可替换地:

{{1}}
相关问题