We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,134 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

php if statement to display image

Im creating a community website and have a little problem working out what my if statment should look like.

there is a default profile image and the one that is stored in the users directory.

so basically i want to display the image which is in the users directory, but if there isnt then display the defualt image. the defualtimage name is saved to the profimage row when the user registers.

Users directory:
users/$userid/images/$profimage

defualt pic
images/$profimage

i have one variable $profimage which completes filepath which basically grabs the filename from the database

i don't know where to start displaying one or the other. Any help would be great. struggling to think.

Thanks

3
Contributors
2
Replies
11 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
brants91
Light Poster
40 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
//keep the whole path including the filename inside the $filename
//this may be users/$userid/images/filename

if (file_exists($filename)) {
    $image = $filename;
} else {
    $image = $default_image;
}

Im not sure if this is what you need??

t_thakar
Newbie Poster
10 posts since Mar 2012
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

for better solution you store path (url) in database and image file in folder

when you fetch record from database that time check url exis or not them check file exist or not

it better solution

rajeevphp2011
Light Poster
26 posts since Nov 2011
Reputation Points: 7
Solved Threads: 6
Skill Endorsements: 1

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0624 seconds using 2.68MB