是否有一种方法,使apache服务器解释文件与.png扩展为.php


Is there a way to make apache server interpret files with .png extension as .php?

是否有办法使apache服务器解释文件与。png扩展为。php?可以用。htaccess吗?

我。htaccess

RewriteEngine On
AddType application/x-httpd-php .php .png
我image.png

<?php
showImage();
function showImage()
{
    $image = @imagecreatefrompng("../aimage.png");
    header("Content-type: image/png;"); 
    imagepng($image );
    imagedestroy($image);
}
?>

不能用

当我去www.example.com/image.png我得到"图像无法显示,因为它包含错误",当image.png为image.php时,它会按原样显示图像

任何想法?

你说你有Apache?将此添加到您的.htaccesshttpd.conf文件中。

AddType application/x-httpd-php .php .foo