View Single Post
Re: a different sig each time
Old
  (#23)
FrostyCoolSlug
Member
 
FrostyCoolSlug's Avatar
 
Status: Offline
Posts: 318
Join Date: Mar 2004
Default Re: a different sig each time - 12-05-2004

ok, here we go then
This script is much longer than the others, but does what its told

PHP Code:
<?php

$filepath 
"images/";
$extentions = Array("PNG""JPG""GIF");

// Open the Directory and clear the files array (JIC)
$handle = @opendir($filepath) or die("");
$files = Array();

// Loop through all the files in the directory
while (false !== ($file readdir($handle))) {
    
// Make sure they are not directories
    
if (!is_dir($file)) {
        foreach (
$extentions as $m00) {
            
// Case insencitive comparison of file extention and
            // Allowed extention
            
if (strcasecmp(getext($file), $m00)) {
                
// Positive Match, add the file to the array
                
$files[] = $file;
                
// Jump out the foreach and tell the while to continue
                
continue 2;
            } 
        } 
    } 

// Make sure there are some files..
if (!count($files)) {
    
// No Valid files were found, kill self.
    
return;
} else {
    
// Choose a random image (the keys are numbers, so can rand them)
    // Use count() -1 because count() starts at 1 and not 0 
    
$img rand(0count($files) - 1);

// Output the file.
readfile($filepath $files[$img]); 

// Function used for fetching extentions..
function getext($file)
{
    
$file explode("."$file);
    return 
$file[count($file) - 1];


?>
I've commented it well, so you know what i'm doing. I've tested it, and know it works

If you have any questions, gimme a shout


=====
Craig "FrostyCoolSlug" McLure
Network Administrator of the ChatSpike IRC Network

Last edited by FrostyCoolSlug; 12-05-2004 at 18:50..
  
Reply With Quote