Solved

Convert Binary String to Image and store locally

Posted on 2008-06-26
2
1,303 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to count occurrences of each item in an array.
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.

757 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

18 Experts available now in Live!

Get 1:1 Help Now