Retrieving Image File from MySQL using PHP
Filed Under (Tech Talk) by Belutz on 31 March 2005
Many people ask me about this.
Database example:
database name = “test”
table name = “image”
table column 1 = id, data type = int, special attributes = auto_increment, primary key
table column 2 = image, data type = blob
this is the sql script:
use test;
create table image (id int(11) NOT NULL auto_increment, image blob, PRIMARY KEY(id));
this is the php script:
<?
header(“Content-type: image/jpeg”); // act as a jpeg file
mysql_connect(“your_host”,”your_db_username”,”your_db_password”);
mysql_select_db(“test”); // use the ‘test’ database$query = “select image from image where id = $id”;
$result = mysql_db_query(“test”,$query);$row = mysql_fetch_array($result);
$img = $row['image'];echo (“$img”);
?>
There you go, you will see the image that you store in MySQL database using blob data type.
Enjoy! ![]()









this query is not valid in my php mysql.image uploading process..this query i work in my prg..follwoing error occur ..
Parse error: syntax error, unexpected ‘:’ in C:\xampp\htdocs\im1.php on line 2
please help me…
@ mahendran
what is on line 2 in your im1.php ?
Hi,
Its working fine with image. Am trying to use the same for audio and video file. But its not working y?
Can u send me the code for storing and retriving audio and video file from mysql database? please..
This does not work for me
I get the link to my site and that’s it
http://localhost/pages/imageview.php
Hi,
You have given the code to retrieving image from mysql, can you please give me the code to store image in mysql.
With regards,
your code just hang out while displaying image
it take lot of time or i should say it hang up while displaying page
@bhavin
I created that script a long time a go, still using php 4 and I forgot what version of MySQL that I use back then. Maybe you have to revise the script a little bit to make it work. Or maybe there are a better way to do that right now in the blogosphere
This code is not working.Please send complete code to store and display.
Thanks in advance
This code showing like this
Warning: Cannot modify header information – headers already sent by (output started at C:\wamp\www\image_galary\show.php:7) in C:\wamp\www\image_galary\show.php on line 8
ÿØÿàJFIFddÿìDuckyw,.ÄÞä±&äë^ ¯1¬½úV1¢Av¨Ú?j\›þ†DÁ„ §’º_QV®äLe…¦sªÙÑŸ³ì¸›„AåÄÅeŸ!”R1³o5úøWEsZæuy“¹[Û Yæ¾ç^ÔÐÅ•4Â)¥ãÔà:@שÕ-8·d¦/qwnÅí&Ly¸1(1þá$,x¢LGÍìm9W¡±ÌÜÚu‡-øû{#»vyí½Ï·œŒK¤ÑYrqÛæF<5æ§‘¯{c‘‘˜y¼Ž=¶§°WCœ^€½h ôlh..GÝR@ä£ÄÐT½EíDÜqt Tõ[ð¹·.M쨔úmÝ @س˜¬‰Õû6s¯—戟â¾"«“ßV_$vvDØ“aãejåÕKøÊ¾¹K*2'@,TóÒ±šá×MܶâijH#/`Ü#T¼âV2Þ𘜡[•ÒÜj‘lµƒÜ&«ð¶ŽTÄ/Ý·è,V“{Ël†â!‡È¿‰µëJìGu-Ê´ºÆÑ±`m˜©‹…A* VÑÖ´ÏT¬}1‹j²’sƒ&S”t@Êx·ûS ¦B€°Y ŽÜrÁÿ~³úP7ˆÇÓjÐCîxÅ$û€yò5¤Â){†M£-S,ÛçÐH51¿?úMSË ‰Zq²`ȉfÖHœ]]MÁx•›*F2Æ’£#¨*ÂÄ ?ê¡™“sÚœ®Zž¶Æo•Ç1u±÷s÷ð¨ÂrçXþŽïø¡&ÆÅûˆÝA]$T‘z´df*VEþ™#X»GÓ®öØ2$m·>=¿G\yãû3«^¾“ãÑÓza9u½¯lÞ„,3åÅÈXÅWAø«³ÛãSO—*öŸy°ÿSPe¹6¬–ùÝcÓæ?¥0dïlÆ„õXÉ’ó>¿Â¬‰; \›f‚¯»wjÉ•ÿÌÙÈŸ-®$œkC™¿2*“`ã„U¹b¬Ú’y“V!‰TƒÁu5″Bh0–4‘ 8¸I¼ –FÿÜýÑ1ƃÿ[üéÂ…þ·â}ÕLÌ‹NŰcmtF:¥me”ñ’øV•Œ ˜â$…Q©« !%¹ó4(€ B 0¸4#¦ôÞqòä)Õ?¡5³zw”³GosTEiéÛ}y*=ÊOê*~0îOðƒ,Ò?±@_x½©³cê¸ÁØs{·ät©ñ-H ‘ôÀaW„·¦s° p˜Ñ¯Ô}´l( (ô‰ @Z€µ@Z€¶” Ò§ N…ð a@¶ -@Z-@PÿÙ
this is the output i get when i run this script.
please help with the right script to get the image in is original format… thanks
�PNG ��� IHDR�������������0���sBIT|d���� pHYs��t��tk$�����tEXtCreation Time�12/05/08|�����tEXtSoftware�Adobe FireworksO�N��’�prVWx�u{ip�vG~ZfF ���&n���W� �
@bernd
that script was using older version of PHP and MySQL. I haven’t test it yet using the current version
I would like to ask please, do not have examples of programs based on the histogram image retrieval using the PHP language, if I have sent to my email-wanto03@gmail.com. please help
tolong kasih pencerahan….
bagaimana caranya menyimpan nilai bin-bin histogram kedalam database menggunakan script php?dan bagaimana cara menampilkan dalam halaman browser. tolong dikirim kealamat E-mail saya ya!mohon konfirmasinya dan terima kasih
thanx it’s great and works fine