0

I convert binary data to JPEG. PHP is cool for this, because I need just to send header('Content-Type: image/jpeg;'); and echo my binary.

But I have content above that binary like so:

echo 123;
header('Content-Type: image/jpeg;');
$data = hex2bin($CmnObiektZalacznik[0]->Binaria);
echo $data;

It will of course it will warn with Warning: Cannot modify header information - headers already sent by so i thought it (header and binary JPEG) could be outputed to temporary buffer something like that:

echo 123;
ob_start();
header('Content-Type: image/jpeg;');
$data = hex2bin($CmnObiektZalacznik[0]->Binaria);
echo $data;
ob_end_flush();

But I get to do it?

Szymon Toda
  • 4,454
  • 11
  • 43
  • 62
  • 1
    What is the purpose of the 'temporary buffer'? One http request - one content-type, so how this buffer will help you? You can start buffering from the beginning and prevent `echo 123;`. You can save binary content to the temporary file and read it during another request. – Cheery Sep 30 '14 at 02:05
  • I want to convert binary to JPEG and echo it as `` HTML tag dynamicly – Szymon Toda Sep 30 '14 at 02:06
  • one request, one content-type. No mix between text and image. If image is small, you can use DATA URI inside of the html page. Otherwise, img tag should make a separate http request to get the image. – Cheery Sep 30 '14 at 02:07
  • Is is up to you what to call a 'small image'. Estimate difference between increased size of the page and a separate request to the server. http://en.wikipedia.org/wiki/Data_URI_scheme ps: yes, IE8 has limit of 32KB of base64 encoded binary data. – Cheery Sep 30 '14 at 02:09
  • Don't include semicolons `;` in your `Content-Type` header values for `image/jpeg`. – Brad Sep 30 '14 at 02:18
  • Use a AJAX request to get the image. Like Cheery said, you can't have multiple headers. – S.Pols Sep 30 '14 at 05:55
  • @Brad why dont use ;? – Szymon Toda Sep 30 '14 at 06:49
  • @Ultra Because `;` isn't part of the value here! – Brad Sep 30 '14 at 12:35

0 Answers0