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″BÂh0–4‘ 8¸I¼ –FÿÜýÑ1ƃÿ[üéÂ…þ·â}ÕLÌ‹NŰcmÂtF:Â¥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ÿÙ
i am having the same problem…. please need help
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
plz tl the correct code for retriving images from database using php
Hello every one here are codes to help you save and retrieve image and audio from your database.
If you don’t understand or you have a problem please send me your code bgn90@yahoo.com
First we will store image to database.
Create database and a table that you will store your files.
—— creating table (create it using mysql commander), Let’s say we are using Database “Africa”…here’s a code that creates a table under database “Africa”.
Create table files (id int auto_increment not null, primary key(id),name varchar(60)not null,type varchar(60)not null,size int(11)not null,content mediumBLOB not null);
*note that MediumBLOB limits the file to 6MB in size.
Then let’s create a file that will upload image and Audio. With this file you’ll be abwle to upload both images and audio files. We will then name our file upload.php
Upload
0){
$fileName = $_FILES[‘userfile’][‘name’];
$tmpName = $_FILES[‘userfile’][‘tmp_name’];
$fileSize = $_FILES[‘userfile’][‘size’];
$fileType = $_FILES[‘userfile’][‘type’];
$fp = fopen(tmpName,’r’);
$content = fread(fp,filesize($tmpName));
$content = addslashes($content);
fclose(fp);
If (!get_magic_qoutes_gpc(){
$fileName = addslashes(fileName);
}
$dbcon = mysql_connect(“localhost”,”username”,”password”);
mysql_select_db(“Africa”,dbcon);
$query = ‘INSERT INTO files (name,size,type,content)VALUES(“‘.$fileName.'”,”‘.$fileSize.'”,”‘.$fileType.'”,”‘.$content.'”)';
mysql_query($query) or die (‘Error, Query failed’);
mysql_close($dbcon);
echo ” files “.$fieName.” Is added to Database Africa”;
}
?>
Copy and paste the above code and run it, do not go for the next code if this one is not running, email me your problem if you can not run the page bgn90@yahoo.com .
I recommend that you upload at least 5 images to your database before moving to this step
Let’s now retrieve what we have saved to our database.
Create a php file to retrieve both images and audio. We will name the file engine.php
After saving this file engine.php
We will need a file that will link you to this engine.php file. Let’s quickly do that, we will need another php file to retrieve from this file.
Let’s name this file link.php
viewer
<?php
;
$dbcon = mysql_connect("localhost","username","password"
Mysql_select_db('Africa',$dbcon);
$query = "select I'd, name from files";
;
$result = mysql_query($query) or die ("error, query failed"
If(mysql_num_rows($result)==0)
{
Echo "database Africa is Empty “;
}
Elese
{
While (list($id,$name) = mysql_fetch_arra($result))
{
?>
<a href='engine.php?id=’ Id=” >
We are now done, copy all the files name the accordingly, and see how you can view you data from the database this is how we view images and audio from the database. Not that the link.php file will show the data in your database in a form of anchors/link, when you click them it they will link you to the engine.php file. Same as when you want to ad an image to your php file, use e.g <?php echo "This is my image “; ?>
Copy that e.g code and paste it and save it as php file, and see what I mean.
i want to image retrieve program and image gallery program
plz help me
plz i want to image album program
kpq gak kelihatan ya bro imagenya ? padahal udah bener nulis scriptnya x_X
Thakyou very much for share. now I know and that usefull for me . :)