PHP in a image file
Moderator: General Moderators
PHP in a image file
I want to somehow create a php script, like image randomizer or something, and then save the script as php file, but with png extension, and then when the image should be outputted, it runs the script as a PHP script, like somehow telling the server to execute the file as a php file, and not as an image. So it would just be a PHP file, but with .png extension. The file should then be able to be runned from a different page.
Is this possible?
Is this possible?
very much so, check out my avatar, its a random image
.
step 1:
make a httaccess with this code:
save it as ".htaccess"
step 2:
put the code below in notepad and save it as "*.png", * = file name that u want.
make sure you define a correct path to a images folder for $folder!!!!!
step 3:
upload both files to your server and go to http://www.yoursite.com/imagefile.png.
hope that helps.
step 1:
make a httaccess with this code:
Code: Select all
AddType application/x-httpd-php .pngstep 2:
put the code below in notepad and save it as "*.png", * = file name that u want.
make sure you define a correct path to a images folder for $folder!!!!!
Code: Select all
<?php
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Thu, 11 May 1983 08:52:00 GMT");
Header("Pragma: no-cache");
$folder = ".";
/* no need to edit the settings below */
if($handle = opendir($folder))
{
while($files = readdir($handle))
{
if ($files != "."
&& $files != "..")
{
$g[] = $files;
}
}
}
$t = array_rand($g);
header("Location: $g[$t]");
?>upload both files to your server and go to http://www.yoursite.com/imagefile.png.
hope that helps.
ALL files in $folder's path will be processed, i suggest you only keep .png files in there.
but if you want to only process .png gile then use this:
but if you want to only process .png gile then use this:
Code: Select all
<?php
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Thu, 11 May 1983 08:52:00 GMT");
Header("Pragma: no-cache");
$folder = ".";
/* no need to edit the settings below */
if($handle = opendir($folder))
{
while($files = readdir($handle))
{
if ($files != "."
&& $files != ".."
&& strstr($files, ".png"))
{
$g[] = $files;
}
}
}
$t = array_rand($g);
header("Location: $g[$t]");
?>I'd suggest using mod_rewrite for Apache.
http://httpd.apache.org/docs/misc/rewriteguide.html
http://httpd.apache.org/docs/misc/rewriteguide.html
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA