Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/76306-non-php-files/
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/76306-non-php-files/#findComment-386313
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.