Run an Image (PNG, JPG) as PHP Script: A Step Guide

By | April 17, 2020

An image can be run as a php script? The answer is yes. In this tutorial, we will use an example to illustrate you how to do.

Edit .htaccess

You can open your .htaccess and add content below.

RewriteEngine on
RewriteRule ^(.*?).png$ test.php?q=$1

Create a php file

This file is called to test.php, you can add content below.

<?php
echo $_GET["q"];
?>

Open a url that ends with .png

For example, you open url: http://127.0.0.1/test/123.png

You will get the result:123

run image as php

The file type of 123.png is an image, however, it runs a php code.

Category: PHP

Leave a Reply