Jump to content

[SOLVED] PHP misterously adds a space to an images binary stream, please help...


Recommended Posts

Hi,

 

i have a rather simple "image protection" script. It reads the original filename out of the database, converts that name to the name that the image is saved on the server, hence the protection, because this name has a hash in it and so on...

 

now the problem..

 

When i try to display the jpeg again, with the following code :

 

// Send the attachment headers.
header('Pragma: ');
if (!$context['browser']['is_gecko'])
	header('Content-Transfer-Encoding: binary');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
header('Accept-Ranges: bytes');
header('Set-Cookie:');
header('Connection: close');
header('Content-Type: image/jpeg');


$fp = fopen($filename, 'rb');

while (!feof($fp))
	{
		echo fread($fp, 8192);
		flush();
	}
fclose($fp);

 

it does read the contents of the image, flushes it to the browser, but it adds a misterious space "%20" or Hex 20 to the beginning of the binary stream. When i take a hex editor and remove this space, the image shows up like it should.

 

Can anyone tell me where this extra space is coming from?

 

thanx !!!!

I tried the Trim method the following way :

 

$fp = fopen($filename, 'rb');

while (!feof($fp))
	{
		$data = fread($fp, 8192);
		trim($data);
		echo $data;
		flush();
	}
fclose($fp);

 

Problem remains :(.. first lines of the output :

 

 ÿØÿà�JFIF�,,��ÿá:âhttp://ns.adobe.com/xap/1.0/�<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.1-c034 46.272976, Sat Jan 27 2007 22:37:37        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""

 

Still includes the space...

         

Found it...

 

	if (function_exists('ob_get_level'))
	{
		while (@ob_get_level() > 0)
			@ob_end_clean();
	}
	else
	{
		@ob_end_clean();
		@ob_end_clean();
		@ob_end_clean();
	}

	$fp = fopen($filename, 'rb');
	while (!feof($fp))
		{
			$data = fread($fp, 8192);
			trim($data);
			echo $data;
			flush();
		}
	fclose($fp);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.