Hi,

first of all, this problem has been stopping me from making any progress with my CakePHP application for 2 days by now, but as far as I can tell it's a general PHP problem (means it occurs in a standalone script as well). However, since I know there are some very smart & experienced php folks on this group I hope somebody might be able to help me out on this one anyway. (I also suspect the issue is not related to my code but to my local setup).

So the problem is the following: I want to use a Controller to serve jpg images stored outside the webroot folder to the visitors of the site I'm working on. Essentially I just want to use PHP to output the contents of a file to the browser. This should be the easiest thing in the world, but I'm experiencing a Heisenbug where in some cases not the entire image is displayed but rather only the top part of it and the rest is either left blank or (partially) covered with random patterns (like when a DivX encoded video turns bad and some frames have lot's of green or such in them). This happens with all pictures I use, even so if I put those images in the webroot they display just fine. And as I said, sometimes (25-33%) the bug does not occur at all and there is no problem (therefor I call it a Heisenbug).

The code I use looks like this:
--------------------------------------------------------------------------------------------------------
$pictureFile = Picture::getPath($picture);       
$fileSize    = filesize($pictureFile);

header('Content-Type: image/jpeg');
header('Content-Length: '.$fileSize);
      
$fp = fopen($pictureFile, 'rb');
fpassthru($fp);
fclose($fp);
--------------------------------------------------------------------------------------------------------

Now I tried various things to fix this. I used a loop to output the image. I used readfile. I used echo file_get_contents(), I used ob_flush() and flush() but nothing seemed to have any effect. One thing that seemed to slightly decrease the problem (more of the image get's displayed) was to put usleep() function calls inside a loop that's echo & fread'ing the picture. Adding an echo "Hello"; statement at the end of the function and turning off the image/jpeg header (and thus looking at the raw output) unveiled that the problem is definitely caused by parts of the output getting lost. Because the length of the output varied and most of the times the "Hello" at then end was missing.

Being on the edge of going insane I also uploaded the script to my web host to see if this behavior would also exist on other platforms - it does not! So chances are there is something wrong with my local setup, and the php code is just fine. Here is what I'm currently running on:

Windows XP - no service pack (got a legitimate copy, but their patches seem to be incompatible with my hardware ...)
PHP 4.4.1 (that's what runs on my web host, I just updated to it from 4.4.0 to make sure the bug is not due to my old version)
Apache 2.0.55

I already checked douzens of php.ini options related to output buffering, memory limits, and such things, but no success. Oh and another very important point is that my script executes completely, even if output get's lost. I checked this by saving the contents of the image file into a variable, dumping the variable content and then saving it to a new file. The resulting image file displayed just fine, the dumped variable content produced the Heisenbug that gives me headaches ...

Alright, I'm close to either killing myself or to reconfigure my entire development environment, so if anybody has the slightest idea what could be going on here, please let me know. The last days have been bad already since one of my SVN repositories went bad (and was unrecoverable) and now this ... Time for a vacation I guess ... : /.

And again, sorry for this being off topic but I'm pretty desperate.
Felix Geisendörfer aka the_undefined

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to