Onetoomanysodas Posted November 7, 2007 Share Posted November 7, 2007 How could I allow Apache to accept a request for an image file (png) but have php analyze a script by that name in a certain directory? Client request => xx.com/test.png PHP Script name: test.png Apache executes php.exe on test.png test.png => Returns image headers and outputs png data Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted November 7, 2007 Share Posted November 7, 2007 Firstly, I wouldn't really recommend doing it the way your thinking as in doing so all .png files will be processed as php. Having said that, all you need do is add... AddType application/x-httpd-php .php .png to your .htaccess file. This forces all .png files to be processed as php. Then your image script.... <?php header("content-type: image/png"); imagecreatefrompng('image.png'); imagepng($image); imagedestroy($image); ?> A better method may be to have a simple image.php file which is passed a filename via the url.... <?php if (isset($_GET['img'])) { header("content-type: image/png"); imagecreatefrompng($_GET['img']); imagepng($image, '', 75); imagedestroy($image); } ?> You can then have a mod_rewrite rule which will allow urls like /images/foo.png to display foo.png as processed via php. Something like.... RewriteRule ^/images/(.*)$ image.php?img=$1 [L] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.