Jump to content

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


houseofdreams

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.