Apache to read a PNG as PHP


#1

I’m trying execute a PHP file by using a PNG extension. How would I do this? So far all I have is this in my .htaccess file.

AddType application/x-httpd-php .png
AddHandler application/x-httpd-php .png

The result of of calling script.png is Firefox popping a download box instead of displaying the PHP+GD rendered image.


#2

No. That is, not the way to go about it.

Leave the extension as PHP, remove that stuff from .htaccess and make sure something like this:

header(‘Content-Type: image/png’);
ImagePNG($x);

…is in your PHP script.

And WTF is up with the [pre] tag?


#3

Well, I need the extension to be PNG. The site that I’m planning to use it in filters PHP extensions for some reason. And I already have that in the script. It’s just calling it properly through another extension is the problem.


#4

In that case, try adding the code I posted (with the “$x” changed to the appropriate variable name) and leave your .htaccess the way it is - might still work.


#5

I kind of fixed it. I thought it might be getting kind of confused with the files so I separated the files in to their own directory with the .htaccess file. But. . . this causes another issue.

Now I’m getting this error;
Fatal error: Call to undefined function: simplexml_load_file().

All I did was copy the working PHP script with a PNG extension. I also tried using a symbolic link as well. So, apache can’t find the function with in a PNG file but it can in the PHP file? I think.

FYI: I’m using PHP 5.


#6

[quote]Now I’m getting this error;
Fatal error: Call to undefined function: simplexml_load_file().[/quote]
Hafta admit, I haven’t the slightest notion what’d cause this.

Just a thought (…without seeing your source code in total), but it looks like whatever script you’re trying to create is the proverbial “Ten pounds of whatever in a five-pound bag”. I use scripts to process graphics (…usually for simple stuff like thumbnailing and watermarking) and I tend to keep the graphics processing as a separate process from the rest of the output.

The long and short of which is, the xml call is out of my experience - you needs yerself someone what’s smarter than me.