Re: searching for a file
| From: | CJD | Date: | Mon, 10 Sep 2001 20:29:30 +0000 |
| Subject: | Re: searching for a file | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-9304@lists.php.net to get a copy of this message | ||
if you know the name of the file, and the directory, then use:
if (file_exists("directory/filename.jpg")) {
print "found";
}
Watch out for case sensitive OS's tho. x.jpg != X.JPG
A more complete method for searching a directory would be:
$handle=opendir('.');
while (($file = readdir($handle))!==false) {
if (strtolower($file)==strtolower($filetolookfor)) {
print "Found";
}
}
closedir($handle);
If you also wanted to check if the file WAS a JPG, then your could add the
following to the if statement:
if ($img=getimagesize($file)) {
if ($img[2]==2) {
print "JPG";
} else {
print "Not a JPG";
}
} else {
print "No a graphic at all";
}
"Afan" <afan@sprout.net> wrote in message
news:OMELIICIPMLGMJHBLMEEOEBICJAA.afan@sprout.net...
> Hi to all,
> how can I search folder with images for the image some_name.jpg and find
> does it exist or not?
>
> Thanks for any help!
>
> Afan
>