tags:

views:

318

answers:

6

I need to be able to tell if an image exists in a directory or not. Given the file name and the directory, how can I tell if it exists?

Thanks!

+4  A: 
file_exists($filename);

http://www.php.net/file_exists

Schnalle
It's important to note that `file_exists` will return true for a directory as well as a file; if you also want to make sure that it's really a file, you want `is_file` instead.
Ben Blank
+4  A: 
$dir = '/var/img/'; $name = 'img.jpg';

echo is_file($dir.$name);
powtac
+1  A: 
bool file_exists(string $filename)
TStamper
+1  A: 

If you need to know more than file_exists() you should look at the stat function... It can tell you if a file exists and if so how big it is, and what type of file it is (and about a dozen other things)...

dicroce
+1  A: 
<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
?>

Source: http://in.php.net/file_exists

NinethSense
A: 

You are talking about image... possibly you try to find a way to put some "no-picture" image instead of nonexistent?

If yes - look at something like this. Else read the manual as people said before...

Jet