Solved

Convert Binary String to Image and store locally

Posted on 2008-06-26
2
1,304 Views
Last Modified: 2013-12-12
I'm hoping this question is fairly simple but i'm having some trouble with it.
I'm trying to convert a binary string into an image.  I'm using a system where you call a web service to request an image and they send it back in binary format.  I'm to use this to store the file locally.  I"m having trouble storing this locally.

Here is some information about the data being returned:

MIME-Version: 1.0
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: multipart/parallel; boundary="AABBCCDD"; charset=utf-8

And this is an example of the binary data being returned that i want to store as an image:

--AABBCCDD Content-Type: image/jpeg Content-ID: 1234 Object-ID: 0 ýýýýJFIF``ýýC    $.' ",#(7),01444'9=82<.342ýýC  2!! ... --AABBCCDD--

I know this data has boundaries set so i need to grab what's in between and store the image locally.  I'm hoping this can be done in PHP.

If more information is needed please let me know.
Any and all help is much appreciated.
Thanks in advance.

Adam
0
Comment
Question by:ahanley409
2 Comments
 
LVL 20

Accepted Solution

by:
virmaior earned 500 total points
ID: 21883346
how are you getting the image?

that looks like curl output.

what are you getting the data from?  (that would determine what you need to do in order to clip the headers).

basically, something like this:
$start_pos = strpos($my_string,'ýýýý');
$my_image = substr($my_string,$start_post,strlen($my_string) - $start_pos);
$my_file = fopen('c:\\temp\\temp.jpg','w');
fwrite($my_file,$my_image);
fclose($my_file);
0
 

Author Closing Comment

by:ahanley409
ID: 31471134
Yes it was curl output :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now