2

I have an Apache web server that has a sub folder for images. For some reason, a few of the .png files are returned as text/html and not as image/png.

There is nothing indicating a permission problem and the files return with code 200 and with full size. I made sure that image/png is set and even tried forcing it with .htaccess

Any idea where to look next?

Edit: looks like an .htaccess configuration problem on a parent directory.

Oren
  • 33
  • 2
  • 8

3 Answers3

1

Did you make sure png files are valid image files? If you are on a Linux platform you can try the file command

file somefile.png

That command should return something along the lines of

PNG image data, 318 x 15, 8-bit/color RGB, non-interlaced

You can also try to view the file with a image viewer.

Can Kavaklıoğlu
  • 968
  • 1
  • 8
  • 11
  • logo.png: PNG image data, 256 x 256, 8-bit/color RGBA, non-interlaced the same file opens on all windows machines i have. i also made sure it wasnt broken in scp / wget – Oren Nov 20 '11 at 16:20
  • Did you try different web browsers? Maybe there is a problem with the one you are using? Could you post a link for us to test? – Can Kavaklıoğlu Nov 20 '11 at 16:23
  • Sorry, cant put a link, but i tried other browsers on other hosts. Looking at the http response i can tell its not a client side problem. – Oren Nov 20 '11 at 16:26
  • Are you using compression options of Apache? This page http://httpd.apache.org/docs/2.0/mod/mod_deflate.html indicates a configuration inorder not to compress image files.[page]: – Can Kavaklıoğlu Nov 20 '11 at 16:38
  • ok, i found the cause. changing the file name did the trick (not every file name i choose work). it must be something in one of the parent directory's .htaccess files Thanks for the help – Oren Nov 20 '11 at 16:57
  • interesting : ) glad it worked out. – Can Kavaklıoğlu Nov 20 '11 at 16:59
1

The problem for me was that the image file to be delivered was named pear.php.net-sos8j3lis2j.png.

Apache's AddHandler directive - that's used to assign the PHP interpreter to .php files - supports multiple extensions, and pear.php.net.png was seen as having three extensions: .php, .net and .png. .php was the first, to the php interpreter was invoked.

text/html was then sent out by either apache or PHP, I don't know.


What I had to do to fix the problem:

Replace all instances of

AddHandler php-cgi .php

with

<FilesMatch \.php$>
    SetHandler php-cgi
</FilesMatch>
cweiske
  • 781
  • 1
  • 13
  • 36
0

Maybe look for .png, .PNG, .pNG and .PNg.

Sandman4
  • 4,045
  • 2
  • 20
  • 27