Re: Problems displaying an image from a controller action using readfile()

2008-05-25 Thread lauren49


Tried imagejpeg() instead of readfile()...didn't work:(
-- 
View this message in context: 
http://www.nabble.com/Problems-displaying-an-image-from-a-controller-action-using--readfile%28%29-tp17443713p17458347.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Problems displaying an image from a controller action using readfile()

2008-05-25 Thread lauren49



Dave J-2 wrote:
 
 
 try setting
 $this-autoRender = false (instead of setting the layout to
 empty), this way Cake won't send anything out to the browser.
 
 also, you might want to try:
 header('Content-Type: image/jpeg');
 (notice the 'jpeg' instead of 'jpg')
 
 

Hey Dave, thanks for the suggestions. Sorry for the delayed reply. I posted
this on Google Groups and had no idea how to find it! 

So I gave your suggestions a try---I also threw in an exit(200) to replace
the die(), just for kicks but the problem persists.

code
Configure::write('debug', 0);
$this-autoRender = false;
$file = APP . 'uploads' . DS . 'memorials' . DS . $id . DS . 'photos' .
DS . 'thumbs' . DS . $file_name;
header('Content-Type: image/jpeg');
header('Content-Length: ' . filesize($file));
readfile($file);
exit(200);
/code

So, in FF the result I see displayed in the browser is simply the requested
URL: http://devel.domain.com/controller/displayFile/4/2.jpg/thumb. However
if I view source I see what looks to be the content of the image (just a
snippet below):
ÿØÿà� JFIF�  �� � ��ÿþ�;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality
= 75 ÿÛ�C�  

I went to bed last night thinking about what may potentially be causing this
problem---didn't come up with much. I _can_ view images successfully using
the readfile() method with a test script that does not involve CakePHP so
I'm still inclined to think Cake is the culprit. But what would Cake be
doing other than adding headers---which from my original post seem to check
out ok. I'm still stumped.

If I force a download of the file with:
header('Content-Disposition: attachment; filename=' . basename($file) .
';');
I can successfully view the file in Photoshop however if I open the
downloaded file using FF the same result is produced where I only see the
path to the image displayed:
file:///C:/Documents%20and%20Settings/Administrator/Desktop/2.jpg
and the view source shows the image file's contents. I'm not sure what
that tells me though...
-- 
View this message in context: 
http://www.nabble.com/Problems-displaying-an-image-from-a-controller-action-using--readfile%28%29-tp17443713p17458274.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Problems displaying an image from a controller action using readfile()

2008-05-25 Thread lauren49


Tried $controller-disableCach() which adds the following headers:

header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
header(Last-Modified:  . gmdate(D, d M Y H:i:s) .  GMT);
header(Cache-Control: no-store, no-cache, must-revalidate);
header(Cache-Control: post-check=0, pre-check=0, false);
header(Pragma: no-cache);

Didn't work:\
-- 
View this message in context: 
http://www.nabble.com/Problems-displaying-an-image-from-a-controller-action-using--readfile%28%29-tp17443713p17458501.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Problems displaying an image from a controller action using readfile()

2008-05-25 Thread Dave J

Hi Lauren,

that code that you're using should work fine, in fact I've tried it on
this end, and it works perfectly.

The only thing that comes to mind at this point, is to check your
controller file (or any file in your app folder), and check for extra
carriage returns at the very end of the file (after the ? closing
tag), which might be screwing things up because they get sent to the
browser before the headers, messing up the image.


On May 25, 4:30 pm, lauren49 [EMAIL PROTECTED] wrote:
 Tried $controller-disableCach() which adds the following headers:

 header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
 header(Last-Modified:  . gmdate(D, d M Y H:i:s) .  GMT);
 header(Cache-Control: no-store, no-cache, must-revalidate);
 header(Cache-Control: post-check=0, pre-check=0, false);
 header(Pragma: no-cache);

 Didn't work:\
 --
 View this message in 
 context:http://www.nabble.com/Problems-displaying-an-image-from-a-controller-...
 Sent from the CakePHP mailing list archive at Nabble.com.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Problems displaying an image from a controller action using readfile()

2008-05-24 Thread Dave J

Hi Lauren,

try setting
$this-autoRender = false (instead of setting the layout to
empty), this way Cake won't send anything out to the browser.

also, you might want to try:
header('Content-Type: image/jpeg');
(notice the 'jpeg' instead of 'jpg')

See if that helps

Dave


On May 23, 9:52 pm, lauren [EMAIL PROTECTED] wrote:
 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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Problems displaying an image from a controller action using readfile()

2008-05-23 Thread lauren

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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---