houseofdreams Posted May 12, 2007 Share Posted May 12, 2007 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 !!!! Quote Link to comment https://forums.phpfreaks.com/topic/51110-solved-php-misterously-adds-a-space-to-an-images-binary-stream-please-help/ Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 try echo fread(str_replace("%20", " ", "$fp")); Quote Link to comment https://forums.phpfreaks.com/topic/51110-solved-php-misterously-adds-a-space-to-an-images-binary-stream-please-help/#findComment-251593 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 LOL and risk messing up the data! trim would work better.. anyways are you sure its on the read and not the insert ? Quote Link to comment https://forums.phpfreaks.com/topic/51110-solved-php-misterously-adds-a-space-to-an-images-binary-stream-please-help/#findComment-251595 Share on other sites More sharing options...
houseofdreams Posted May 12, 2007 Author Share Posted May 12, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/51110-solved-php-misterously-adds-a-space-to-an-images-binary-stream-please-help/#findComment-251597 Share on other sites More sharing options...
houseofdreams Posted May 12, 2007 Author Share Posted May 12, 2007 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); Quote Link to comment https://forums.phpfreaks.com/topic/51110-solved-php-misterously-adds-a-space-to-an-images-binary-stream-please-help/#findComment-251604 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.