POSFriends
make me some furnitures http://thedailypos.org/friends/index.php?topic=1360.new#new

we're drawing pokemon again, maybe
Register |
  (Advanced search)
Pages: [1]
Topic: Random avatar/sig script  (Read 621 times)
Permalink  •  May 26, 2015, 10:02:19 PM
Random avatar/sig script
« on: May 26, 2015, 10:02:19 PM »

Put this in a folder with your images. Name it index.php. Then link to it as if it were the image.

Code: [Select]
<?php
if ($dir opendir("."))
{
     
$list buildimagearray($dir);
     
displayrandomimage($list);
}

// This function reads all the files in the current directory and adds all image files to the array $list[]
function buildimagearray($dir)
{
     while (
false !== ($file readdir($dir)))
     {
          if (!
is_dir($file) && getimagesize($file))
          {
               
$list[] = $file;
          }
     }
     return 
$list;
}

// This function selects a random image, determines the mime type, opens the file for reading,
// and then outputs the image
function displayrandomimage($list)
{
     
srand ((double) microtime() * 10000000);
     
$sig array_rand ($list);

     
$size getimagesize ($list[$sig]);
 #$filename = $list[$sig] . '?rand=' . uniqid((double)microtime()*1000000,1);
 #$fp = fopen($filename, "rb");
     #$fp = fopen($list[$sig] . '?rand=' . uniqid((double)microtime()*1000000,1), "rb");
 $fp fopen($list[$sig], "rb");

     if (
$size && $fp)
     {
header("Cache-Control: no-store, no-cache, max-age=0, 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("Random: " uniqid((double)microtime()*1000000,1));
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
     }
}
?>

Pages: [1]