Can't display local file

See all posts See thread Reply

Re: Can't display local file new!
by colin, 14 years, 8 months ago
The upload object looks fine.

It seems that you have a problem of headers. Check what headers are being sent to Firefox (you can use LiveHTTPHeaders for that).

You can also try to first output an image to the browser without using the class itself. Code such as (here with PNG images):
header('Content-type: image/png');
readfile($my_png_file);

or
header('Content-Length: '.filesize($my_png_file));
header('Content-Type: image/png');
print file_get_contents($my_png_file);
Reply
Re: Can't display local file new!
by Kim, 14 years, 8 months ago
Hello Colin,

Thank you for helping with this.

I uploaded a png file using this class then tried to access it with both of your code examples and got this error each time: The image “view-source:https://mydomain.com/~lifespa/demo/getfile.php?t=svc&id=7” cannot be displayed, because it contains errors.

Here's the output from LiveHTTPHeaders.

https://mydomain.com/~lifespa/demo/getfile.php?t=svc&id=7

GET /~lifespa/demo/getfile.php?t=svc&id=7 HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)
Accept: image/png,image/*;q=0.8,*/*;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
Referer: https://mydomain.com/~lifespa/demo/index.php?p=service&action=edit&sid=7
Cookie: __utma=63748150.1862303144.1225142372.1260905107.1265309473.21; __utmz=63748150.1256751018.18.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=9b9bf89c40caccf4f6f7f21811be1fa7

HTTP/1.1 200 OK
Date: Wed, 03 Mar 2010 19:37:43 GMT
Server: Apache
X-Powered-By: PHP/4.4.9
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
Reply
Re: Can't display local file new!
by colin, 14 years, 8 months ago
I think your server has a problem when sending headers.

Here are my headers when outputing an image:
HTTP/1.1 200 OK
Date: Wed, 03 Mar 2010 20:44:10 GMT
Server: Apache......
X-Powered-By: PHP/5.......
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/png


As you can see, my Content-Type is image/png when yours is text/html. In fact, if I output the image without sending the headers, I have text/html too. So it looks to me like your PHP may not be outputing the headers properly.

Besides, it is very possible that you output something else than the image (and its headers) before. If, in your script, you echo some text for instance before outputing the image, then you will have the message The image “...” cannot be displayed, because it contains errors..

So I recommend you try with a very simple script to output an image. Check that you don't have anything (HTML...) before the PHP opening tag in your script, and that your script doesn't output anything before the image headers.

Here is the code I use to try it out:
$img = new Upload('test.png');
$img->image_resize = true;
$img->image_ratio_y = true;
$img->image_x = 400;
header('Content-type: ' . $img->file_src_mime);
echo $img->Process();
die();

With this code, you should see image/png in the HTTP headers, and then your image should display. If not, it may be a problem with your PHP installation, or your Apache server. Try it on another setup to make sure that your code works, or doesn't.Reply
Re: Can't display local file new!
by Kim, 14 years, 8 months ago
Hello Colin,

Thank you so much for your help and for creating this class. Turns out the the problem was a PICNIC! Problem In Chair Not In Computer.

Following your advice I tracked the problem down to two blank lines at the end of my defines file.

Thanks Again
Kim CarrReply