quote:
Originally posted by ValSpy
quote:
Originally posted by Ash_
use scan dir to scan for all gif files. (scandir and substr). then load them all into an array get a random namber thats not bigger then count($array); and use that image.
www.php.bet to look up those two functions =)
www.php.bet? i think its .net anyways i have no clue what you just said after all im a total php newbie
lol, you aint gonna learn if i give you the code are you?
code:
<?php
$dir = '/tmp';
$files1 = scandir($dir);
print_r($files1);
?>
that code gets and displays all contents of a folder.
code:
echo substr('abcdef', -1, 1); // f
prints f.
so you could go.
code:
$dir = '/images';
$files1 = scandir($dir);
for ($x=0;$x<count($files1);$x++){
if (substr($files1[$x], -1, 3) == 'jpg') {
$images[] = $files1[$x];
print_r ($images);
}
}
now all the images in the folder are in the $images array.
now we get a random number.
code:
$num = rand(0, count($files1));
all code.
code:
$dir = '/images';
$files1 = scandir($dir);
for ($x=0;$x<count($files1);$x++){
if (substr($files1[$x], -1, 3) == 'jpg') {
$images[] = $files1[$x];
print_r ($images);
}
}
$num = rand(0, count($files1));
echo "<img src='$dir/$images[$num]' />
its not the cleanest way to write it but i should work (not at home at the moment)
[/code]