6 Replies - 3276 Views - Last Post: 15 December 2006 - 05:23 PM

#1 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1167
  • View blog
  • Posts: 7,207
  • Joined: 07-September 06

How can I get Apache to treat image files as php files?

Posted 13 December 2006 - 05:12 PM

Okay well on another of my attempts at making a gamercard application I have now gotten to the point where I have to be able to get a .png or other image file (only a single image file type) to act as a php file. I have seen this done on other sites and it would be great if I could get it to work also.

I want it to be able to take a variable from the url (like a php file) however it will only be using this to get the information that is required for the file.

Then I already have the rest of it.

Also, if it is possible is there any way to create a directory where you can type whatever into the address bar and goto the same page?

Like so: http://www.reigningg...ame_or_gamertag

and have it still goto:

http://www.reigninggames.com/online

but have the information after the final / act like a get variable?

Is This A Good Question/Topic? 0
  • +

Replies To: How can I get Apache to treat image files as php files?

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: How can I get Apache to treat image files as php files?

Posted 13 December 2006 - 05:42 PM

This actually has to do with Apache (or whatever HTTP server you're using), not PHP itself. You can think of how the server does it is, as the server executing php -f /the/file/to/be/parsed.extension. I don't know how how the PHP apache module actually does it, but you can make Apache run PHP scripts just as if you were doing it from the command line.

Anyway, you can add AddType application/x-httpd-php .png to an .htaccess file (assuming your host allows you to use .htaccess files), and Apache will send those file off to be parsed by PHP.
Was This Post Helpful? 0
  • +
  • -

#3 MathewS  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 343
  • Joined: 14-May 02

Re: How can I get Apache to treat image files as php files?

Posted 13 December 2006 - 05:43 PM

To have the .png file act as a .php file you will have to set try this

Add the following code in .htaccess file to run php files without .php extension.

AddHandler application/x-httpd-php .png


You can also add that to cpanel

It is possible to have online be a page and the rest a variable, but i cant remember what it is called at the moment i think it is mod_rewrite

EDIT: Damn

This post has been edited by MathewS: 13 December 2006 - 05:44 PM

Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: How can I get Apache to treat image files as php files?

Posted 13 December 2006 - 05:57 PM

To do the URL based thing you were wondering about, it can be done with either mod_rewrite or making use of the <files> directive and turning "AcceptPathInfo" on.


And matt is right about using Addhandler instead of Addtype.
Was This Post Helpful? 0
  • +
  • -

#5 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1167
  • View blog
  • Posts: 7,207
  • Joined: 07-September 06

Re: How can I get Apache to treat image files as php files?

Posted 14 December 2006 - 07:01 PM

Okay, thansk guys, I will have to try that over the weekend, as I don't currently have the time to do most anything over the week.
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1167
  • View blog
  • Posts: 7,207
  • Joined: 07-September 06

Re: How can I get Apache to treat image files as php files?

Posted 15 December 2006 - 05:14 PM

Update:

Sorry this may be a stupid question but is there any way to make only one .png file act as a .php file? Or is it an all or nothing type of thing?
Was This Post Helpful? 0
  • +
  • -

#7 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: How can I get Apache to treat image files as php files?

Posted 15 December 2006 - 05:23 PM

You certainly can!
<Files /the/path/to/the/file.ext>
ForceType application/x-httpd-php
</Files>


And that's not a stupid question. A stupid question would be either, "How I make admin panel?" or "How I mine for fish?".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1