Endless Paradigm

Full Version: Random Image Generator in PHP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Decided to put this up for anyone interested.

NOTE, requires:
  • A hosting service with PHP support
  • Images must be uploaded to the same folder as the PHP script

Copy and paste this to make a new .php file:

PHP Code:
<?php

// Force no caching
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: image");








//****************** CHANGE THIS PART **************************
//Add lines to add images

$pic = array(
 "1.jpg",
 "2.jpg",
 "3.jpg"
);


//**************************************************************













$rpic = $pic[mt_rand(0, count($pic)-1)];

header("Content-Length: ".filesize($rpic));
header("Content-Type: image");

$fp = fopen($rpic, 'rb');
fpassthru($fp);
fclose($fp);

?>

Upload this file to your server, and direct people to use this .php file as the image.



I chose to use this method as it works better than a header redirect (which typically gets cached).  Also hides the actual files from the user :P

Further reference:
http://endlessparadigm.com/forum/showthread.php?tid=930

i CAN'T BELIEVE YOU!

I asked you loads, and you posted it here..

:(
:/
lawl. yeah i did something with php and images some time ago, was a status image for a thread on a forum which showed the number of posts/pages in the thread and the last poster etc. turned out pretty cool
ty for sharing

also

http://crimsonomen.imeem.com/music/8-pwm..._has_aids/

Necro-Bot

[Image: screaming%20zombie.jpg]
I should use this sometime
2 yr old thread @_@
oh my god.

this was 2 YEARS AGO!?

Holy spoon.
Yeah, its useful
Reference URL's