Shoutbox

Random Image Script (Not KSMAS) - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Random Image Script (Not KSMAS) (/showthread.php?tid=37214)

Random Image Script (Not KSMAS) by user27089 on 01-19-2005 at 09:31 PM

i've been having a lot of trouble lately with the fact that my server doesn't seem to support KSMAS very well, so I was wondering if there were any other free random image scripts out there that I could 'have'... ?


RE: Random Image Script (Not KSMAS) by Plik on 01-19-2005 at 09:34 PM

Heres the one i coded myself for my avatar.

code:
<?php
$dir = "imgs";
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
srand( (double) microtime()*1000000 );
$randnum = rand(0, $filesnum - 1);
readfile($dir . "/" . $files[$randnum]);
?>
It basically randomly pics a file from the imgs folder and uses that as the image.
Note: The file structure has to be
avatar.php
imgs/
and dont stick anyother files in the imgs folder, as it uses them all.
RE: Random Image Script (Not KSMAS) by user27089 on 01-19-2005 at 09:37 PM

Thanks a lot :p...


RE: Random Image Script (Not KSMAS) by Plik on 01-20-2005 at 06:43 PM

Erm apparently theres a security hole in it, ive edited the post with the updated code, that *should* fix the hole


RE: Random Image Script (Not KSMAS) by fluffy_lobster on 01-20-2005 at 06:47 PM

Indeed, nice and secure now :)

Personally, I think it's neater to pick the random image like this though:

code:
<?php
$dir = "imgs";
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
srand( (double) microtime()*1000000 );
$key = array_rand($files);
readfile($dir . "/" . $files[$key]);
?>

RE: Random Image Script (Not KSMAS) by user27089 on 01-20-2005 at 09:34 PM

you could find such things as passwords by adding things like /.. on it :p... lol