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

how can I find out, if file exist in folder, which is password protected via .htaccess (I know password)

This not working:

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


if (file_exist($filename)) {

return TRUE;

} else return FALSE;

but if some other folder dont have .htacces password, this code nicely works:

$filename = "http://website.com/pictures_without_password/12.jpg"; // folder dont have password

if (file_exist($filename)) {

return TRUE;

} else return FALSE;

Thanks

file_exists over HTTP can be finnicky,

Please try the following:

$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;
}

Alternatively:

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;
}