0

I want to make user profile picture who only have account. But I dont know how to insert and display in the page that image form database, please support.

Edited by pritaeas: Removed Skype name. Keep it on-site.

4
Contributors
3
Replies
28
Views
4 Years
Discussion Span
Last Post by IIM
0

Assuming here that you already have raw binary data of the
image in the database, you also need to know the image type.

With these two pieces of information, you can write a
special HTML <img> tag that includes the image data
within the tag:

print '<img src="data:image/jpeg;base64,'.base64_encode($image['file_data']).'" alt="profile picture">';

Whether or not storing binary images in a database is a good practice is an entirely different debate altogether.

Regards, Shawn

0

You should be storing the image's filename in the database. So if you have a table users you could add a column profile_pic, for example. On your server have a directory storing the images (maybe public_html/images/profilepictures).

Then in your PHP code you can combine the directory with the filename to retrieve the image:

<?php 
define('PROFILE_PIC_DIR', '/images/profilepictures');

// query your DB for $user info
...

// Output image
?>
<img class="profile-picture" src="<?= PROFILE_PIC_DIR . $user['profile_pic']?>" alt="" />

Edited by EvolutionFallen: Missing closing PHP tag

1

To store image you can have a separate table in your Database.For eg:-
User[user_id,display_name,pic_id,email_id etc]
Profile_Pic[pic_id,file_type,file_location,file_name,file_size]

Now to insert file refer this or this.While inserting save corresponding data detail in database to map pic with user profile.

To display pic,EvolutionFallen has already provided solution.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.