473,545 Members | 937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MIME attachments stored in mySQL

Hello,

I am parsing a mailbox using the imap functions, pulling out images
attached and putting them into mySQL as BLOB fields. I am having
problems displaying images once they are stored in mySQL, and I think
it may be related to the way I store them.

The following line of code is called after an attachment has been
identified as a GIF attachment:

$rawimage = addslashes(imap _fetchbody($mbo x,$m,$part_c));
....where $mbox is the imap link and so forth.

Testing to make sure I am actually pulling info out, a debug line like:
print_r($rawima ge);

....displays a bunch of chars that are the image attachment data, and a
line like:

print_r(base64_ decode($rawimag e));

....displays other, different chars.
Looks good so far - I'm definitely pulling images out as raw data.

So I INSERT the $rawimage into my blob field.

However, on the display page, I send the headers like:
header("Content-type: image/gif");
[get image from database and store it in a var called $image_from_db]
echo $image_from_db;

But I get a broken image...

So I try print_r($image_ from_db) on this page (after removing the
header line) and it looks like the chars from the tests before - it's
the same data.

base64_decode($ image_from_db) does not make the image display properly,
either, but printing it as such shows all those chars again.

I think I do not understand how base64 encoding and addslashes works
between MIME, php and mySQL. Anybody have any ideas? How should I
format the data when I pull it out of MIME (in terms of base64
decoding), how should I insert it (addslashes is correct?) and how
should I echo it when I pull it out into the displaying php image
generation page?
I have a feeling someone has had this problem before out there :)

Jul 17 '05 #1
6 2804
Hello Matt,

Looks like it could be an addslash problem. Here is the link for your
reference : http://us4.php.net/addslashes

If you site already has magic_quotes_gp c set (=On) in php.ini (which is
the default), your using addslashes() adds an extra set of slashes to
you already quoted data. So the data's original significance is lost.

In your code, you can check to see if the magic_quotes option is set
using get_magic_quote s_gpc() and then use addslashes().

Why don't you try your code without the addslashes()? Everything you
have described seems correct and should give you your required outcome.
If after removing addslashes(), it still does not work, try doing a
stripslashes() on the retrieved image before calling base64_decode() .
Thank you,
--Kartic

Jul 17 '05 #2
Thanks Kartic-- but doesnt magicquotes only affect GET and POSTand
COOKIE data? This data is pulled using the imap_fetchbody( )
function...

Jul 17 '05 #3
Ooops...Yes, you are right.

I meant magic_quote_run time :
http://us2.php.net/manual/en/ref.inf...quotes-runtime and
the corresponding get_magic_quote s_runtime().

Thanks,
--Kartic

Jul 17 '05 #4

And also, take a peek at the user notes for
http://us4.php.net/base64_encode

There is some interesting stuff there that people had trouble with
(similar to yours)
(Look for mightymrj at hotmail dot com, entry dated 28-Oct-2004 11:35.)
Thank you,
--Kartic

Jul 17 '05 #5
Yes, I am missing something here...

Turned off magic_quotes_ru ntime per the suggestion on the base64_encode
man page.

Still corrupted images...

So I try this:
$f = fopen("...etc") ;
fwrite($f, base64_decode($ rawimage));
fclose($f);

...and the pics are well-formed and viewable.
The answer lies in the slashes somewhere, you're right...

Jul 17 '05 #6
Hello,

I found this article that does something similar to what you are trying
to do...(the article uses an image upload page).. have fun.

http://www.onlamp.com/pub/a/onlamp/2...09/webdb2.html

One more thought crosses my mind...why don't you base64_decode() your
MIME image before you store it into the database table?
Thanks,
--Kartic

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7412
by: Sugapablo | last post by:
Is there any PHP function that will allow me to determine the MIME type of a blob stored in MySQL? Specifically, if I'm storing an image as a blob in MySQL, is there any PHP function that can determine whether it's a gif, jpeg, png, etc? -- http://www.sugapablo.com <--music ] http://www.sugapablo.net <--personal ]
4
2718
by: Alberto | last post by:
I am struggling with the php mail function so to allow a multipart mime settings where both the message and any set of attachments can be allowed. Teorically, I'd know how to do. I build up my headers and pass them as the fourth argument of the function mail(). Practically, what happens is that whenever I try to test my script emailing...
3
7703
by: Erik Rosenbach | last post by:
I have a question about how to parse out mime from a message. I have email messages that are stored in a database table and these messages have mime headers embedded within them. How can I parse out this mime content and retrieve only the text messages? Thank you, Erik
0
1369
by: bill ramsay | last post by:
Hello I am writing a program that sends simple text files to a remote device. the files have to be in the format textX.dat where X = numbers in the range 0 up to 10 depending upon the situation. these files are stored in a directory called attachments. The files themselves are single line affairs in ascii.
1
7003
by: John B. Kim | last post by:
I am working on the code below: ****************************************************** use strict; use MIME::Lite; use Net::SMTP; my $from = 'steve@earthlink.net'; my @addweek1 = qw(michael@earthlink.net jennifer@aol.com ); my $Fnameweek1 = 'JNIssue11.pdf';
1
1176
by: NM | last post by:
I need an advise on how to proceed. My understanding is that .net doesn't support mime and attachment web services. First question, is that true? If thats true, is there any tip or how-to document if I really need to access that kind of service? Attachments using mime is quite documented in the WS spec from w3c and also in the Attachment...
3
3275
by: flo | last post by:
hi, i have to develop a web service client (must be .net, currently i'm using c# with wse3) for a java service. the java service uses mime attachments for up- and download of files. i googled around for mime support in .net and only saw "don't do it" ;) (apparently even dime is not possibly in wse3?) so, is there any possibility to use...
0
1645
by: andreas.baus | last post by:
Hello. I'm trying to build a client using .NET/C# that is capable of communicating with an existing Webservice written in Java using Apache Axis. Now, I've encountered a problem trying to retrieve binary data (i.e. downloading files) which is sent by the service using the "SOAP with attachments" format (as per...
3
3822
by: Steven Allport | last post by:
I am working on processing eml email message using the email module (python 2.5), on files exported from an Outlook PST file, to extract the composite parts of the email. In most instances this works fine, the message is read in using message_from_file, is_multipart returns True and I can process each component and extract message attachments....
0
7467
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7807
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.