PHP: Tell me if the file exists?

I need to find out if an image exists in the directory or not. Given the filename and directory, how can I tell if it exists?

Thanks!

+1


a source to share


6 answers


file_exists($filename);

      



http://www.php.net/file_exists

+5


a source


$dir = '/var/img/'; $name = 'img.jpg';

echo is_file($dir.$name);

      



+4


a source


bool file_exists(string $filename)

      

+1


a source


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 and what type of file it is (and a dozen other things) .. ...

+1


a source


<?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

+1


a source


You are talking about an image ... perhaps you are trying to find a way to put a "no image" image instead of a non-existent one?

If so, look at something like this . Else read the manual like people said before ...

0


a source







All Articles