Jump to content

Image Redirect To Other Image


Solar

Recommended Posts

<?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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.