Zend - The PHP Company




Files and Directories

Add Code


spidermanuk  

Type: code fragment
Added by: spidermanuk
Entered: 02/09/2002
Last modified: 09/12/2001
Rating: - (fewer than 3 votes)
Views: 3889
tests to see if an image file (jpg/gif..) exists and if it does not then it can display alternative text! Good to use if your website in underconstrucion and you are waiting for someone else to add images as they get them. No more explorer missing image icons!


<?php
function doiexist($path$findfile
{
// Source = www.spiderandjenni.com/phptips
$found=0;
if (
$dir = @opendir($path)) {
                while ((
$file readdir($dir)) !== false) {
                                        if(
$file==$findfile){$found=1;}
            }  
                  
closedir($dir);
                }else{print 
"no such dir path"$found==2;}

return(
$found);



?>
?>


Usage Example


$findfile1="logo.jpg";
$finddir="logos";
if(doiexist($finddir, $findfile1))
{
    print <IMG SRC='$finddir/$findfile1'>";
}
else
{
    print "the image file is not on the server yet!";
}


Rate This Script





Search



This Category All Categories