Jump to content

Php echo image


hoponhiggo

Recommended Posts

Hi Guys

 

Hoping somebody can help me again please?

 

I have some code which calls and displays all images in the file structure on my webpage.

 

<?php
//to display image from source
$dir = "profpics/";

//opening directory
if ($opendir = opendir($dir))
{
//reading directory
while (($file = readdir($opendir)) !== FALSE)
{
	if ($file!="."&&$file!="..")
	echo "<img src = '$dir/$file' img width='38' img height='38'><br>";
}
}

?>

 

This works fine, but what i want is for only the image that relates to the logged in user to be displayed.

 

Both the user id and image id are stored in the same row of my database

 

 

Sorry if this is confusing. Can anybody help?

 

Thanks

Link to comment
Share on other sites

Hello and thanks for the reply!

 

I'm sorry but I'm a beginner with php an don't quite fully understand your answer. Could you please Ellaborate a little?

 

I have tried to set a variable with a statement to say something like "select * from profile_pics where username = $session [mm_username] but as you probably k ow this didn't work!

Link to comment
Share on other sites

Both the user id and image id are stored in the same row of my database

 

The code you posted isn't working with a database. All I can see is that your opening a directory of images and making sure the file isn't . or .. upon $dir returning TRUE.

 

So where is that code?

 

Do you establish cookies or sessions for the logged in users? If you do then you can add a session variable for the userid.. and anywhere you want to use that the first line in your script will be session_start();

THEN you can query the db for the userid

THEN you can save a value to the session:

$_SESSION['userid'] = $row['userid']

 

or you could simply store the user's image path into a session variable and echo it to display the image, using the same method as above.

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.