bionic25 Posted August 15, 2008 Share Posted August 15, 2008 On an auction listing page im making the user who has uploaded their listings' info can also upload a photo. on the page "listing.php?&id=***" their listing is auto-generated from mysql. part of this auto generated info is an image. As a user can only upload one photo, and their user ID is unique, the html to display this message is: ../images/thumbs/$username.jpg Problem: If they chose not to upload a photo with the listing that ugly broken image symbol is displayed. How can i hide this or have an auto ____________________ | | | NO | | IMAGE | | UPLOADED | | | |___________________|.jpg type file that is default outputed. Thanks for any answers ~bionic25 Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/ Share on other sites More sharing options...
ajclarkson Posted August 15, 2008 Share Posted August 15, 2008 The way I would be tempted to do this would be: When the user signs up in your form handler, check that the image upload isn't empty, and save their image path to the database if it isnt. If it is replace their path with a default one. Hope this helps? Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617307 Share on other sites More sharing options...
lonewolf217 Posted August 15, 2008 Share Posted August 15, 2008 what if you did something like this (pseudo code) if(file_exists(../images/thumbs/$username.jpg)) { output image } Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617309 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Or use the file_exists() function to check for an image if(file_exists($pathToImageFile)) { // display the image echo "<img src=''>"; } Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617310 Share on other sites More sharing options...
ajclarkson Posted August 15, 2008 Share Posted August 15, 2008 why is it that I always forget about the file exists function?! I have written so many work arounds where that would have sufficed. Top advice, ignore my suggestion! Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617316 Share on other sites More sharing options...
bionic25 Posted August 15, 2008 Author Share Posted August 15, 2008 Thanks for the posts they are both solutions. I tried the file_exist one, which seems to fit exactly what I need. this is the new code: if(file_exists("..newCar/thumbs/$username.jpg")) { echo "<img src=\"..newCar/thumbs/$username.jpg\">; } else{ echo "no image"; } problem is, for some reason, when i tested it it will only output "no image" even though the file DEFINITELY exists?! Im new to php so may be problem in code, any ideas?? Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617321 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 You need to use the full path to the image rather than a relative path ie. /var/www/html/mywebsite.com/images/imagefile.jpg Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617323 Share on other sites More sharing options...
bionic25 Posted August 15, 2008 Author Share Posted August 15, 2008 if(file_exists("/***/***/****/*/*/******/public_html/******/images/thumbs/$username.jpg")) { echo "<img src=\"..newCar/images/thumbs/$username.jpg\">"; } else{ echo "no image"; } Right, tried that ^^ but now the entire page isn't working!! I tried removing this section and it worked again?! What is wrong with this code it is confusing the hell out of me, but im sure its a code error (newbie php'er) Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617331 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 No code errors on the screen? How many files are in this directory? Quote Link to comment https://forums.phpfreaks.com/topic/119823-help-with-missing-images/#findComment-617400 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.