Discussion: random pics
Afficher un message
Vieux 14/04/2008, 04h23   #3
while-one
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: random pics

On Apr 13, 7:48 pm, "prophet" <M_Mo...@hotmail.com> wrote:
......or do it server-side with a scripting language, perhaps php

function randPicName()
{
$cnt=-1;
$dir = opendir("/var/www/my-site/my-images/my-rands");
while ( $file = readdir($dir))
{
if($file[0] != ".") /// or call some fancier isImage function
{
$cnt++;
$pics[$cnt] = trim($file);
}
}

srand((double)microtime()*1000000);
$randval = rand(2,$cnt);
$pic = $pics[$randval];

/// this is an image name only, so you'd
/// have to prepend a path to make an img src url with it.
return ($pic);
}
  Réponse avec citation
 
Page generated in 0,04070 seconds with 9 queries