Can't display local file

See all posts See thread Reply

Re: Can't display local file new!
by Kim, 14 years, 8 months ago
When I look at the code in Firefox here is the message I get when I try to view the pic:

The image “view-source:https://thedomain.com/~lifespa/demo/getfile.php?t=svc&id=6” cannot be displayed, because it contains errors.

If I call the picture directly it shows as it should.

While trying to troubleshoot I turned off the header output of the image mime type and was able to see the code from the picture print. But, as soon as I add header('Content-type: ' . $img->file_src_mime); I get the error message above.

To get the output from the object after local image upload I did this:
$img = new upload($imgurl);
print_r($img);

The output is below:
upload Object
(
    [version] => 0.29
    [file_src_name] => 11_svclogo_226116.jpg
    [file_src_name_body] => 11_svclogo_226116
    [file_src_name_ext] => jpg
    [file_src_mime] => image/jpeg
    [file_src_size] => 4909
    [file_src_error] => 0
    [file_src_pathname] => /home/lifespa/uploads/pics/11_svclogo_226116.jpg
    [file_src_temp] => 
    [file_dst_path] => 
    [file_dst_name] => 
    [file_dst_name_body] => 
    [file_dst_name_ext] => 
    [file_dst_pathname] => 
    [image_src_x] => 150
    [image_src_y] => 137
    [image_src_bits] => 8
    [image_src_pixels] => 20550
    [image_src_type] => jpg
    [image_dst_x] => 150
    [image_dst_y] => 137
    [image_supported] => Array
        (
            [image/gif] => gif
            [image/jpg] => jpg
            [image/jpeg] => jpg
            [image/pjpeg] => jpg
            [image/png] => png
            [image/x-png] => png
            [image/bmp] => bmp
            [image/x-ms-bmp] => bmp
            [image/x-windows-bmp] => bmp
        )
    [file_is_image] => 1
    [uploaded] => 1
    [no_upload_check] => 1
    [processed] => 1
    [error] => 
[log] => system information
- class version : 0.29
- operating system : FreeBSD
- PHP version : 4.4.9
- GD version : 2.0.28
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is a local file /home/lifespa/uploads/pics/11_svclogo_226116.jpg
- local file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
Fileinfo PECL extension not available
- Checking MIME type with UNIX file() command
MIME type detected as image/jpeg by UNIX file() command
- MIME validated as image/jpeg
source variables
- You can use all these before calling process()
file_src_name : 11_svclogo_226116.jpg
file_src_name_body : 11_svclogo_226116
file_src_name_ext : jpg
file_src_pathname : /home/lifespa/uploads/pics/11_svclogo_226116.jpg
file_src_mime : image/jpeg
file_src_size : 4909 (max= 52428800)
file_src_error : 0
- source file is an image
image_src_x : 150
image_src_y : 137
image_src_pixels : 20550
image_src_type : jpg
image_src_bits : 8
    [file_new_name_body] => 
    [file_name_body_add] => 
    [file_name_body_pre] => 
    [file_new_name_ext] => 
    [file_safe_name] => 1
    [mime_check] => 1
    [mime_fileinfo] => 1
    [mime_file] => 1
    [mime_magic] => 1
    [mime_getimagesize] => 1
    [no_script] => 1
    [file_auto_rename] => 1
    [dir_auto_create] => 1
    [dir_auto_chmod] => 1
    [dir_chmod] => 511
    [file_overwrite] => 
    [file_max_size] => 52428800
    [image_resize] => 
    [image_convert] => 
    [image_x] => 150
    [image_y] => 150
    [image_ratio] => 
    [image_ratio_crop] => 
    [image_ratio_fill] => 
    [image_ratio_pixels] => 
    [image_ratio_no_zoom_in] => 
    [image_ratio_no_zoom_out] => 
    [image_ratio_x] => 
    [image_ratio_y] => 
    [image_max_width] => 
    [image_max_height] => 
    [image_max_pixels] => 
    [image_max_ratio] => 
    [image_min_width] => 
    [image_min_height] => 
    [image_min_pixels] => 
    [image_min_ratio] => 
    [jpeg_quality] => 85
    [jpeg_size] => 
    [preserve_transparency] => 
    [image_is_transparent] => 
    [image_transparent_color] => 
    [image_background_color] => 
    [image_default_color] => #ffffff
    [image_is_palette] => 
    [image_brightness] => 
    [image_contrast] => 
    [image_threshold] => 
    [image_tint_color] => 
    [image_overlay_color] => 
    [image_overlay_percent] => 
    [image_negative] => 
    [image_greyscale] => 
    [image_text] => 
    [image_text_direction] => 
    [image_text_color] => #FFFFFF
    [image_text_percent] => 100
    [image_text_background] => 
    [image_text_background_percent] => 100
    [image_text_font] => 5
    [image_text_position] => 
    [image_text_x] => 
    [image_text_y] => 
    [image_text_padding] => 0
    [image_text_padding_x] => 
    [image_text_padding_y] => 
    [image_text_alignment] => C
    [image_text_line_spacing] => 0
    [image_reflection_height] => 
    [image_reflection_space] => 2
    [image_reflection_color] => #ffffff
    [image_reflection_opacity] => 60
    [image_flip] => 
    [image_rotate] => 
    [image_crop] => 
    [image_precrop] => 
    [image_bevel] => 
    [image_bevel_color1] => #FFFFFF
    [image_bevel_color2] => #000000
    [image_border] => 
    [image_border_color] => #FFFFFF
    [image_frame] => 
    [image_frame_colors] => #FFFFFF #999999 #666666 #000000
    [image_watermark] => 
    [image_watermark_position] => 
    [image_watermark_x] => 
    [image_watermark_y] => 
    [allowed] => Array
        (
            default array )

    [forbidden] => Array
        (
        )

    [translation] => Array
        (
            default array        )

    [language] => 
    [lang] => en_GB
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