View Single Post
Re: a different sig each time
Old
  (#24)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: a different sig each time - 12-05-2004

hehe thanks

I've made it a lil bit shorter

don't forget to close the directory handle in your code btw...
Code:
<?php
 
$handle = opendir (getcwd ()) or die ();
$files = Array ();
$file_count = 0;
 
// loop through all the files in the directory
while (($file = readdir ($handle)) !== false)
{
   if (is_dir ($file))
	  continue; // discard directories
 
   $ext = strstr ($file, "."); // get the file extension
 
   // is this file of one of the allowed extensions ?
   if ((strcasecmp ($ext, ".png") == 0)
	   || (strcasecmp ($ext, ".jpeg") == 0)
	   || (strcasecmp ($ext, ".gif") == 0))
   {
	  $files[$file_count] = $file; // yes it is, add the file to the array
	  $file_count++; // we know now one image more
   }
}
 
closedir ($handle); // finished, don't forget to close directory handle
 
// did we find no image ?
if ($file_count == 0)
   return; // if so, don't output anything at all.
 
// output a random image file among those in the array
readfile ($files[rand (0, $file_count - 1)]);
 
?>



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."

Last edited by Pierre-Marie Baty; 12-05-2004 at 19:16..
  
Reply With Quote