Hi,

So I've had this working perfectly. The images are stored above the
webroot

/app
    /uploads
        img01.jpg

The controller has an action which accepts the file name of the image,
adds some HTTP headers and outputs the image contents using
readfile().

Now I can't be 100% sure but it seemed to start happening after I
enabled Cake's caching feature. However, I've since disabled it but
the problem remains.

I've spent a few hours debugging this and here is what I've come up
with so far:

I can get the images to display correctly in my browser with a simple
test script (no Cake) containing the following code:
$file = 'path/to/img001.jpg';
header('Content-Type: image/jpg');
header('Content-Length: ' . filesize($file));
readfile($file);

So to me that rules out Apache or PHP as potential culprits.

========================================
The HTTP headers from my test script
========================================
http://localhost/test.php

GET /test.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:
1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Date: Fri, 23 May 2008 19:47:02 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.3
Content-Length: 2116
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpg
----------------------------------------------------------

========================================
The HTTP headers from the request in Cake:
========================================
http://devel.domain.com/controller/displayFile/4/2.jpg/thumb

GET /controller/displayFile/4/2.jpg/thumb HTTP/1.1
Host: devel.domain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:
1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: CAKEPHP=crtafp53f202pombn3cmj83og5

HTTP/1.x 200 OK
Date: Fri, 23 May 2008 19:48:03 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.3
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Content-Length: 2120
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/jpg
----------------------------------------------------------

I've tried removing the P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP
IND DEM" but that didn't solve the problem.

Also, here a stripped version of the code in the controller's
displayFile() action:

function displayFile($id, $file_name, $type=null) {
    Configure::write('debug', 0);
    session_destroy();
    $this->layout = '';

    header('Content-Type: image/jpg');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}

I'm hoping someone can shed some light...

- Lauren

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to