almightyegg Posted February 19, 2007 Share Posted February 19, 2007 Image question 1 I want all my members to log on and all have the same default image called default.jpg and if they upload a new image then it is called userid.jpg (must be jpg) how would I do a search to see if there was an image called $mem[id].jpg and if there isn't show default.jpg? Image question 2 Each member also has a main image which is set in the site as the same one, but with different colours etc. But in the site they can add things to the image eg. they click that they want a bandana and it adds it to the image.I know it's possible but I don't know whether it is in php...My limits are php html and css Thanks for reading Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 19, 2007 Share Posted February 19, 2007 For question 1: If your storing it in a mysql database, you could simply set the image field's default value to default.jpg. Otherwise I don't exactly understand how your doing your image checking. For question 2: http://www.php.net/manual/en/ref.image.php You will need to have PHP's GD library installed. Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 19, 2007 Share Posted February 19, 2007 For question one, you might consider looking at http://us2.php.net/manual/en/function.file-exists.php. The first example provided might do what you need. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 For question one, you might consider looking at http://us2.php.net/manual/en/function.file-exists.php. The first example provided might do what you need. $file = '/images/players/a$mem[id].jpg'; if(file_exists($file)){ echo "<img src='http://www.lordoftheabyss.com/images/players/a$mem[id].jpg'>"; }else{ echo "<img src='http://www.lordoftheabyss.com/images/players/default.jpg'>"; } There is a file called a1.jpg (my id is 1) and yet it still doesn't show For question 2: http://www.php.net/manual/en/ref.image.php You will need to have PHP's GD library installed. Thanks I'll take a look Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 You need to use the full path for file_exists You might even use a boolean in the Database for default - if it's 1, show the default, if 0, they have an image - that might work easier. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 I looked up boolean and it looks complicated but my script still doesn't work with the full path Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 19, 2007 Share Posted February 19, 2007 <?php $file = '/images/players/a'.$mem[id].'.jpg'; ?> Try that. Make sure to echo your file path if you are troubleshooting. I believe the other way you had it was creating "a$mem[id].jpg", instead of replacing the ID. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 True. False. Not really complicated... But I think JBS solved it Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 Still didn't work...is there any other errors on my code: $file = 'http://www.lordoftheabyss.com/images/players/a$mem[id].jpg'; if(file_exists($file)){ echo "<img src='http://www.lordoftheabyss.com/images/players/a'.$mem[id].'.jpg'>"; }else{ echo "<img src='http://www.lordoftheabyss.com/images/players/default.jpg'>"; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 You didn't change what JBS posted... Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 Oops! I'm slow alas, no joy still though. $file = 'http://www.lordoftheabyss.com/images/players/a'.$mem[id].'.jpg'; if(file_exists($file)){ echo "<img src='http://www.lordoftheabyss.com/images/players/a'.$mem[id].'.jpg'>"; }else{ echo "<img src='http://www.lordoftheabyss.com/images/players/default.jpg'>"; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 That's a url not a path. File exists won't work with a URL, it needs the path. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 is the path going to be public_html/images/players/a'.$mem[id].'.jpg? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 Yes, only there is probably even more to it - you know when you get an error message and it says in file.... and there's a really long path? That's the whole path. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 is there any fast way to find it??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 try print $_SERVER['SCRIPT_FILENAME']; on the file and see what it outputs. Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 19, 2007 Share Posted February 19, 2007 You can force an error and get the path as Jesi said. <?php echo "Force Error" echo "Force Error" ?> Should produce something similar to... Parse error: syntax error... in /path/path/path/path/path on line x Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 19, 2007 Author Share Posted February 19, 2007 Cool! It works now thanks you guys another happy customer 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.