Solved

Convert Binary String to Image and store locally

Posted on 2008-06-26
2
1,308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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