How to run php script in png/jpg extension

10,551

Add the following line to your .htaccess file

AddHandler application/x-httpd-php .png

This tells the server to process all files ending with .png as .php.

Share:
10,551
McGrasus
Author by

McGrasus

Updated on June 04, 2022

Comments

  • McGrasus
    McGrasus almost 2 years

    How can i edit .htaccess file to make client run php script, but in png/jpg extension. Soo... User will visit url

    http://example.com/script.png and he will see "test"(php script will return this value), not image. That's what i already did: .htaccess file:

    AddType application/x-httpd-php .png
    

    script.png file:

    <?php
    header("Content-type: image/png");
    echo 'test';
    ?>
    

    What is wrong with this code? Why it doesn't work? Browser tries to download the image :/

  • McGrasus
    McGrasus about 9 years
    seems to doesnt work for me, browser tries to show image
  • McGrasus
    McGrasus about 9 years
    what do you mean? "image on the directory"? @Starkeen
  • Amit Verma
    Amit Verma about 9 years
    I think the problem is with your script.png file, as other users have already suggested in their comments you are using wrong Content type, change the content type to text/html , or remove this, You have already told your server to read png as php
  • Raptor
    Raptor over 6 years
    If the directory / virtual host is set to AllowOverride None, the settings in .htaccess will not be working.
  • Amit Verma
    Amit Verma over 6 years
    @Raptor That's true!!