[Cialug] RE: Using conditional logic within PHP

Barry Von Ahsen cialug@cialug.org
Fri, 05 Nov 2004 12:03:45 -0600


if(file_exists("/unix/path/to/$HH_ID.jpg")) {
	echo "<a href=''>Click here</a>";
} else {
	echo "No photo";
}

if you know the real path you can use it - 
file_exists('/var/www/photos/photo.gif') or if you don't, you can use 
getcwd() which will get your current working directory 
($apacheroot."/pages/whatsnew" for your page below).  then you can do:
file_exists(getcwd()."/../../photos/$HH_ID.gif")

http://us2.php.net/manual/en/function.file-exists.php
http://us2.php.net/manual/en/function.getcwd.php


-barry



Andrew Lietzow wrote:
> Hello LAMP brainiacs. I Need help with "if then else" logic in with PHP and HTML. 
> 
> Here is a page that lists some plants. 
> http://hostahaven.com/pages/whatsnew/HH_ID.php
> 
> For some of the items, I have a photo while for others, I have not at present.  I'd like to add a conditional statement that checks for the existence of the jpg file in the appropriate directory, and if it doesn't exist, print the text "No Photo" rather than "Click for Photo". 
> 
> I assume I can do some kind of file checking, like 
> $file=fopen("foo","r") or die("Error!"); 
> but I'm a bit lost on the foo and the r.   In place of foo, could I put  "http://domain.com/photos/"+$HH_ID+'.jpg'     ? where HH_ID is item number to the left of the .jpg?   
> 
> This tutorial gets me close to an answer (e.g. http://www.htmlgoodies.com/php/p11filesystem.html) but doesn't clarify how I check for a file in a particular directory.  
> 
> Hints would be greatly appreciated.   
>   
> Andrew Lietzow
> 
>      
> 
> 
> _____________________________________________________________________
> Get your own family web site at www.MyFamily.com!
> 
> 
>