473,402 Members | 2,053 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,402 software developers and data experts.

retreiving image from database(blob)

pradeepjain
563 512MB
hii,
i have stored the images from form to database in blob format.now i have a necessity to retrieve image from database and store it in a folder ..how to do this..


thanks,
Pradeep
Jul 29 '08 #1
7 7173
Hi, I've found this to be very helpful: http://www.phpriot.com/articles/images-in-mysql
It shows how to display the image on page 8. Hope it helps :o)
If you still need help, post the structure if your table and how you'd like to show the images to the user (ie, <img src="img.php?id=..."> or direct url or what way you'd like to use).

Regards,
Tom
Jul 29 '08 #2
pradeepjain
563 512MB
i hve used that script .....but that doesnot work for me bcos i wanted to mail the picture which i am not able to do .so i that of saving the picture fron database to some jpg file and then mailing it....

i am sending the mailing script chk if u can help
[PHP]<?php
mysql_connect("localhost","root","12233");
mysql_select_db("xyz");

$str_sql="select * from pphp where id=184";
//'".$_GET['Id']."'";
$Colloquiums1 = array();
$i=0;

$res_id=mysql_query($str_sql);
while ($sub_row=mysql_fetch_array($res_id)) {
$tmp1 = array(
'Count' => $i+1,
'ID' => $sub_row['ID'],
'pic' => $sub_row['pic']
)
$Colloquiums1[$i++] = $tmp1;
}
$ID=$Colloquiums1[0]['ID'];
$nid=$ID;
$name=strtoupper($Colloquiums1[0]['name']);
$picname=$Colloquiums1[0]['picname'];
$address=$Colloquiums1[0]['address'];
//$pic=print("<img src='/phdstudents/admitcardpic.php?Id=184'>");
// multiple recipients
//$to = 'aidan@example.com' . ', '; // note the comma
//$to .= '<REMOVED-BY-MOD>@gmail.com';

// subject
$subject = 'admitcard';

// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<div id="textcontent">
<h3>Admit Card</h3>
<table align="center" width="100%" border="1" cellspacing="2" cellpadding="2" id="img1">
<tr>
<td align="left">Ref=' . $ID .'</td>
</tr>
</table>
<table align="center" width="100%" border="0" cellspacing="2" cellpadding="2" id="img1">
<tr>
<td>Name</td>
<td>:</td>
<td><b>' . $name . '</b></td>
/*problem here in mailing the pic*/
<td colspan=2>' . <img src="http://abc.com/abc/pic.php?Id=190"> . '</img></td>
</tr>

<tr>
<td>Address</td>
<td>:</td>
<td><b>' . $address . '</b></td>
</tr>
</table><table>This is a automated email(admitcard) generated.Copyright@IIA.</table>
</body>
</html> ';

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: <REMOVED-BY_MOD>@gmail.com, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: webmaster <webmaster@iiap.res.in>' . "\r\n";
$headers .= 'Cc: testcom' . "\r\n";
$headers .= 'Bcc: cc@example.com' . "\r\n";

// Mail it
$ok=mail($to, $subject, $message, $headers);
if($ok){
echo "mail sent";
}
else{
echo "fail";
}

?>
[/PHP]
Jul 29 '08 #3
ak1dnar
1,584 Expert 1GB
Hello Pradeep,
I think you you can do this by adding one more header to your mail script.
Expand|Select|Wrap|Line Numbers
  1. $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
Now we need the real file name as the attachment, Let me say, I never tried to take it directly from MySQL blob and put it in to header.But I think we can do it( Guys, correct me if I'm wrong here). Why don't you give it a try, until I also do some coding for this.

Accideblty you have added a email address to the script and I am assuming that was your personal email. for your own safety and also because of the rules of our forum I had to remove it.
Jul 29 '08 #4
Atli
5,058 Expert 4TB
I'm not sure this is the best way to send images in emails, but you can "embed" images into HTML by using a data URL scheme as the src.

Like, for example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Fetch the image. Could be replaced with your database data
  3. $filename = "img.jpg";
  4. $data = file_get_contents($filename);
  5.  
  6. // Encode the data and send it using an <img> tag
  7. $data = base64_encode($data);
  8. echo '<img src="data:image/jpeg;base64,', $data, '" alt="testing..." />';
  9. ?>
  10.  
A modern browser should display this just like a normal <img> tag using the file name as a src.
Jul 29 '08 #5
ak1dnar
1,584 Expert 1GB
I'm not sure this is the best way to send images in emails, but you can "embed" images into HTML by using a data URL scheme as the src.

Like, for example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Fetch the image. Could be replaced with your database data
  3. $filename = "img.jpg";
  4. $data = file_get_contents($filename);
  5.  
  6. // Encode the data and send it using an <img> tag
  7. $data = base64_encode($data);
  8. echo '<img src="data:image/jpeg;base64,', $data, '" alt="testing..." />';
  9. ?>
  10.  
A modern browser should display this just like a normal <img> tag using the file name as a src.
Yes, I am just talking about mail with file attachments here. May be the OP is asking about sending inline images with his email. but original post doesn't say anything about it.
Jul 30 '08 #6
pradeepjain
563 512MB
hey guys i got thse solution i cld mail picture by using

<img src="http://www.abc.com/pic.php?Id='. $nid .'"></img>



Thanks,
Pradeep
Jul 30 '08 #7
hey guys i got thse solution i cld mail picture by using

<img src="http://www.abc.com/pic.php?Id='. $nid .'"></img>



Thanks,
Pradeep
Hello,

That's not a solution, that's a work-around. To be honest, I don't know the solution to what you need, but you should look into MIME. There are PHP classes out there that support MIME attachments (try looking on google) and you can include images in email messages. Using an <img> tag doesn't help very much because almost all email clients block images and the user has to click on something to unblock them and allow them to load which may not always be acceptable. Also, if someone is saving that email on their computer they might not get the image from some clients, they'll only get the html with the tag so if they'll be disconnected from the Internet or if you decide to change the URL by which the image is accessed, they won't see the image. Another thing to take into account is bandwidth. Every time someone will look at an email, their client will connect to your web server to check if the image has updated and some clients might even re-download the image every time.

The <img> be OK for what you need, but I thought you might want to consider the things from above and decide if you need to use MIME.

Regards,
Tom
Aug 1 '08 #8

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

Similar topics

5
by: Rob | last post by:
Ummm...I'm a little stuck on how to approach the following.... I have a mySQL table holding images (fields are: data (blob), name (text), type (text), size(text), desc (text) ) If I want to...
3
by: David Stockwell | last post by:
Hi, I'd like to read the contents of a file into memory. The problem is that this file is binary. I then want to store the whole thing in memory to a database as a blob. I have no problem...
2
by: tracy | last post by:
I plan to change the datatype from long raw to blob as from tables stud_photo and cimpant _image below. But i am not sure if it is a good idea. pls advise. TQ! SQL> DESC STUD_PHOTO; Name ...
5
by: ssp | last post by:
Dear all, I'm dealing with a very tricky problem and can't seem to find the answer with google. the problem is: i want to store huge data (binaries) inside a mysql databases blob - to later...
2
by: Olav Tollefsen | last post by:
How can I display photo images stored in a SQL Server 2000 databases in a DataList or DataGrid without having to write the images to files first? Olav
4
by: Piedro | last post by:
Hi group, how do I read a image/blob field in cas option strict is on? First I had it turned off and I read it like this: Dim b() As Byte If Not dsSupp.Tables(0).Rows(0).Item("BITMAP") Is...
1
by: Mikael | last post by:
I'm fairly new to Access, however I have decent experience with a variety of programming languages. I created a database for students profiles at my company. The profiles contain various data, plus...
0
by: bananularstyle | last post by:
Hi everyone, This is an issue I have been picking away at for the past two weeks and am running short of ideas. :-\ I am writing an ASP page that allows a user to open/save a tif image stored on...
4
by: Connie | last post by:
I have a column in my table that is an Image (blob). The data stored in this blob is basically pdf files. I need a query to determine the total size of these blob's in the database. Here is what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.