Reputation: 950
In my apache logs I see a lot of:
Attempt to serve directory: somedir/ This error appears because I dont allow directory browsing.
Now I know that they appear when someone enters a page where the database thinks it have a picture and then return an empty field thus when I do:
background-image: url("somedir/{$value[self::PICTURE]}");
and there is no picture it will look at the directory insted somedir/
To avoid this I made if(is_file("somedir/{$value[self::PICTURE]}")) but I still see the errors. Now my question is what is the best approach to check if a file is present without getting an apache error log entry if the file is not there?
Upvotes: 1
Views: 304
Reputation: 2272
You need to make sure that the variable you're checking for is set. Like :
if ( isset ( $file ) && file_exists ( $file ))
Upvotes: 1
Reputation: 12420
If you want to use a PHP variable within a string, you should use double quotes instead of single ones. That may be the reason why your script fail.
$path = 'somedir/' . $value[self::PICTURE];
if (is_file($path) || is_dir($path)) {
// Your logic here
}
Upvotes: 0