Solar Posted September 21, 2009 Share Posted September 21, 2009 <?php $req_user_info = $database->getUserInfo($req_user); echo "<img src=\"http://URLHERE/photo/".$req_user_info['username']."\"\width=\"400\" height=\"300\" >"; ?> I have this script up and running, it shows the User's Profile Picture IF they have uploaded one, is there a code that could find in my folder "photo" the username's photo "Doesn't even have an extension", but if they don't have a PHOTO, redirect to a photo like called unknown.png. I've got the start and don't know where to be pointed to, I don't ask anyone to write the code for me as to I would like to learn, but is greatly appreciated for help. Solar Quote Link to comment https://forums.phpfreaks.com/topic/174953-image-redirect-to-other-image/ Share on other sites More sharing options...
redarrow Posted September 21, 2009 Share Posted September 21, 2009 easy way forward <?php $req_user_info = $database->getUserInfo($req_user); if($req_user_info){ echo "<img src=\"http://URLHERE/photo/".$req_user_info['username']."\"\width=\"400\" height=\"300\" >"; }else{ echo "no pic"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/174953-image-redirect-to-other-image/#findComment-922062 Share on other sites More sharing options...
itaym02 Posted September 21, 2009 Share Posted September 21, 2009 What you should do is update the user table with it's image filename the moment the user uploads one. Before he uploads one the default should be unknown.jpg etc Quote Link to comment https://forums.phpfreaks.com/topic/174953-image-redirect-to-other-image/#findComment-922064 Share on other sites More sharing options...
Solar Posted September 21, 2009 Author Share Posted September 21, 2009 easy way forward <?php $req_user_info = $database->getUserInfo($req_user); if($req_user_info){ echo "<img src=\"http://URLHERE/photo/".$req_user_info['username']."\"\width=\"400\" height=\"300\" >"; }else{ echo "no pic"; } ?> Works like a charm, I added a Exclamation mark because it wasn't working and re-arranged some wording; Soultion: <?php $req_user_info = $database->getUserInfo($req_user); if(!$req_user){ echo "<img src=\"http://URLHERE/photo/".$req_user_info['username']."\"\width=\"400\" height=\"300\" >"; }else{ echo "no pic"; } ?> Thanks again bro. I didn't like to do with mysql, thats why I needed coding like this.. Perfect. Quote Link to comment https://forums.phpfreaks.com/topic/174953-image-redirect-to-other-image/#findComment-922068 Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 The above only displays a "no pic" if ther is no user... what if there is a user, but no pic? <?php // open the specified directory and check if it's opened successfully $dirPath = 'photo/'; if ($handle = opendir($dirPath)) { // keep reading the directory entries 'til the end $npg='1'; while (false !== ($file = readdir($handle))) { // just skip the reference to current and parent directory if ($file != "." && $file != "..") { if (is_dir("$dirPath/$file")) { // found a directory // do not think about it } else { // found an ordinary file // use $file $req_user_info = $database->getUserInfo($req_user); if($req_user_info['username']===$file || !$req_user){ echo "<img src=\"http://URLHERE/photo/".$file."\" width=\"400\" height=\"300\" >"; }else{ echo "no pic"; } } } } // ALWAYS remember to close what you opened closedir($handle); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/174953-image-redirect-to-other-image/#findComment-922084 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.