lAZLf Posted December 17, 2009 Share Posted December 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/ Share on other sites More sharing options...
anthylon Posted December 18, 2009 Share Posted December 18, 2009 I don't understand why would you store images in database? Keeping images in database doesn't seem as nice idea to me. :-\ I would suggest to keep images in regular folders/sub-folders and keep only path to them in database if required. Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979665 Share on other sites More sharing options...
phpSensei Posted December 18, 2009 Share Posted December 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979672 Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979678 Share on other sites More sharing options...
lAZLf Posted December 18, 2009 Author Share Posted December 18, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979765 Share on other sites More sharing options...
anthylon Posted December 18, 2009 Share Posted December 18, 2009 No man! That would be suicide - your database would be huge and toooo slow. 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 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979778 Share on other sites More sharing options...
lAZLf Posted December 18, 2009 Author Share Posted December 18, 2009 ^....that makes a lot of sense.... Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979791 Share on other sites More sharing options...
lAZLf Posted December 18, 2009 Author Share Posted December 18, 2009 I got it now, thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/185535-database-image-displaying-script/#findComment-979797 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.