mikefrederick Posted October 9, 2007 Share Posted October 9, 2007 How can I display an image w/ php only if it exists. the images are uploaded via a user, and the image is placed in a folder called propertyimages and the image name is placed in a table called image1 inside of a database. then when it comes time for them to be displayed, I am connecting to the database and using the following script to show the image: <? echo '<img src="propertyimages/'.$row_Rs['imageone'].'" height="200" width="200" vspace="10" hspace="10" >'; ?> now how can I alter this so that it will only show if it actually exists? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 9, 2007 Share Posted October 9, 2007 http://ca.php.net/manual/en/function.file-exists.php Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted October 10, 2007 Author Share Posted October 10, 2007 I do not know how to use that function in this case. It detects that it exists everytime I think. My problem basically is that the page that the images are displayed on displayes boxes with x's where the image should be if it was not uploaded .I tried the following with no success: $filename = 'propertyimages/'.$_row_Rs['imageone']; if (file_exists($filename)) { echo '<img src="propertyimages/'.$row_Rs['imageone'].'" height="200" width="200" vspace="10" hspace="10" >'; } else { echo " "; } Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted October 10, 2007 Author Share Posted October 10, 2007 anyone? Quote Link to comment Share on other sites More sharing options...
skein Posted October 10, 2007 Share Posted October 10, 2007 are you using MySQL? if you are you can use mysql_querry and just check if the file you entered is in the database and if it is it will show it. Quote Link to comment Share on other sites More sharing options...
ikmyer Posted October 10, 2007 Share Posted October 10, 2007 I would just check if there is a file name in the database and then if there is... output the <img> tag accordingly. That would have to assume your upload code works correctly. To me that seems easier then trying to check if a file exists. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.