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
.
Author by
McGrasus
Updated on June 04, 2022Comments
-
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 about 9 yearsseems to doesnt work for me, browser tries to show image
-
McGrasus about 9 yearswhat do you mean? "image on the directory"? @Starkeen
-
Amit Verma about 9 yearsI 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 over 6 yearsIf the directory / virtual host is set to
AllowOverride None
, the settings in.htaccess
will not be working. -
Amit Verma over 6 years@Raptor That's true!!