Jump to content

database image displaying script


lAZLf

Recommended Posts

So I found this script (http://www.wellho.net/mouth/937_Display-an-image-from-a-MySQL-database-in-a-web-page-via-PHP.html) to display images from a database, the only thing I don't know is what type of data (blob, binary, etc) should the image be in the database, and how to insert an image into the database.

Link to comment
https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/
Share on other sites

This will overload your database, not really but its just so much data your inputting.

 

Rather than inserting the entire image data stamp just put in the url where it resides in your server. As mentioned by the user above, store the images in a folder, and store the name of the image file in your database.

So I found this script (http://www.wellho.net/mouth/937_Display-an-image-from-a-MySQL-database-in-a-web-page-via-PHP.html) to display images from a database, the only thing I don't know is what type of data (blob, binary, etc) should the image be in the database, and how to insert an image into the database.

 

Yes. This should only be used if you have a mission critical PHP project that requires major portability. Imagine 100 people view your web page, over 200+ entries would be made to your database alone just to pull out an image. Slow and choppy. Databases were meant for text, atleast classically with PHP.

I need to store images in a database because i'm creating a forum-ish page on my website and I want to be able to get each persons avatar next to their posts. Similar to how this forum pulls out peoples avatars. Do forums do this through something else and not a database?

No man! That would be suicide - your database would be huge and toooo slow.  :o Think once again - instead of storing image in database you will store simple images/forum/avatar/user_x_avatar_0001092whatever_unique_name.jpg. Actually here is what you should have:

1. in config file somewhere you should have stored path to user avatars: $avatar_path = example images/forum/avatar

2. in user table add additional field: img_avatar and store name of image assigned for user

 

There you go! Next time when you need to show image for specific user just echo image HTML elements. Example:

<img id="avatar" class="img_avatar" src="<?php echo $avatar_path .'/' .$row['img_avatar']" width="80px" height="80px"> 

 

Buddy, do whatever you want but don't store image in database :-\

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.