473,382 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

how to store image in Mysql database

hi
i need help..how can i store image in mysql database
and i want to retrive that image
can anyone suggest plz
Feb 8 '07 #1
8 12200
there is BLOB datatype in Mysql

to put it in, read image file with file_get_contents() function and put content into mysql query
Feb 8 '07 #2
Motoma
3,237 Expert 2GB
there is BLOB datatype in Mysql

to put it in, read image file with file_get_contents() function and put content into mysql query
Thank you for your response stephane!
Feb 8 '07 #3
Expand|Select|Wrap|Line Numbers
  1. <form name="form1" enctype="multipart/form-data" method="post" action="">
  2.   <input name="file1" type="file" id="file1">
  3.   <input type="submit" name="Submit" value="Submit">
  4. </form>
  5. <?
  6. $f=$_POST['file1'];
  7. mysql_connect("localhost","root","");
  8. mysql_select_db("real");
  9. mysql_query("select * from reg");
  10. //$file_u=$_POST['file1'];
  11.  
  12.  
  13.  
  14.                 $val = '0x' . bin2hex($f);
  15.                 $qu="insert into `reg`(`file`)values('$val')";
  16.  
  17. mysql_query($qu) or die("Query Error");
  18. print '<h1 align="center">File Successfully Uploaded</h1>';
  19. ?>
  20.  

Here i inserted the image in database.its stored as BLOB 2BYTES
and i tried to retrived by using this code
Expand|Select|Wrap|Line Numbers
  1. <?
  2. mysql_connect("localhost","root","");
  3. mysql_select_db("real");
  4. $q=mysql_query("select * from reg");
  5. while($log=mysql_fetch_array($q))
  6. {
  7.  
  8. print file_get_contents($log['file']);
  9. }
  10. ?>
  11.  
i dint get the image.....
Feb 8 '07 #4
while($log=mysql_fetch_array($q))
{
print file_get_contents($log['file']);
}

.
why u use file_get_contents here?
i think it must looks like this
Expand|Select|Wrap|Line Numbers
  1. while($log=mysql_fetch_array($q))
  2. {
  3. print $log['file'];
  4. }
  5.  
and don't foget to send image/jpg ( or other ) before
Feb 8 '07 #5
Motoma
3,237 Expert 2GB
{

print file_get_contents($log['file']);
}
This is wrong, first, you need to specify the content type: jpeg, gif, png, etc...
Second, you aren't opening a file, so file_get_contents() should not be used.

You will want to do something more like this:
Expand|Select|Wrap|Line Numbers
  1. {
  2. header("Content-type: image/png");
  3. echo $log['file'];
  4. }
  5.  
Hope this helps.
Feb 8 '07 #6
Here i tried...
print $log['file'];
but the result came as OX
plz give me an solution
Feb 9 '07 #7
Nert
64
Here i tried...
print $log['file'];
but the result came as OX
plz give me an solution
Hi hemashiki,

according to you, you have already save image to database right? now you want to retrieve the image?
here try this code, i've come up with this code when i encountered the same problem as yours.

Expand|Select|Wrap|Line Numbers
  1. mysql_connect("localhost","root","");
  2. mysql_select_db("real");
  3. $q=mysql_query("select * from reg") or die(mysql_error());
  4. $log = mysql_fetch_object($q); 
  5. header("Content-type: image/GIF");    
  6. echo $log->file; 
hope this would help you too.

--nert (^_^)
Feb 9 '07 #8
Here i tried...
print $log['file'];
but the result came as OX
plz give me an solution
because you insert to base at the same hex format
$val = '0x' . bin2hex($f);
it's wrong, you must insert simply file content, returned file_get_contents function
Feb 9 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Cezus | last post by:
Good day, Im a beginner at C# and i use the book Visual C# 2005: How to program from Deitel/Pearson. I want to build a simple Anime (movie) database. It contains a list box with all the anime...
1
by: rabik83 | last post by:
hai I store the image to the Mysql database its sucess so how can i get the IMAGE from the database please sent the code .........URGENT thanks
2
by: sookfuny1984 | last post by:
I am facing a problem on how to parse (analyze) apache log file (access or error file) so that the data in log file will be imported to MYSQL database?? anyone can help?
1
by: berry | last post by:
Hi all, I am scratching my head on how to store image that user upload to the MySQL database in vb6? Please HELP me!! Thank you very much..
3
rajiv07
by: rajiv07 | last post by:
Hi to all, We can store image in mysql using MEDIUMBLOG data type.I want to know how to insert or select and store an image data type using perl. Is any idea Please Thanks. Regards ...
1
by: shanmukha | last post by:
sir,we are doing STIGNOGRAPHY project.my problem is how to store picture in database table?i know only text,and number.
3
by: dakshayini | last post by:
Hi all, i need to store data having subscript and super script like chemical equations symbols...values in to mysql database and fetch it and display. for that i need to convert that text into...
2
selvasoft
by: selvasoft | last post by:
hi how to store image in database using JSP
0
selvasoft
by: selvasoft | last post by:
Please any one help me i want store my image to oracle database am using JSP here is my code.But this code will return Null Pointer Error. What is wrong with this code. Am using HTML form to browse...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.