0

I want to upload a PHP file to a server under a PNG extension, while still being able to view it in my browser as a PHP file. How can I do that? Thanks.

Anon
  • 1
  • 1

4 Answers4

2

Use the following in your .htaccess file in the directories where your files are:

<FilesMatch "\.png$">
    SetHandler application/x-httpd-php
</FilesMAtch>

Note that ALL files with .png will be handled by PHP with this.

roychri
  • 2,866
  • 1
  • 21
  • 29
1

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.

Andreas
  • 5,305
  • 4
  • 41
  • 60
0

Why not use URL Rewriting for this?

cotton.m
  • 455
  • 2
  • 10
-1

You cannot. PHP is server-side code and is not rendered in the browser.

  • 2
    What? You can configure apache to fire up the php interpreter for any file extension. You can also have it treat it as plain text so the PHP is viewable. It's not clear what OP wants. – Mike B Mar 14 '12 at 13:26