<?php
$path = "/Homes/elmio/";
$nombredir = "imagenes";
   
function cuentaficheros($nombredir) {
$numerodefichs=0;
if (is_dir($nombredir)) {
  if ($dir = opendir($nombredir)) {
  while (($nombrefich=readdir($dir))!=false)
    if ((!is_dir($nombredir . "/$nombrefich"))&&($nombrefich{0}!="."))
    $numerodefichs++;
  closedir($dir);
  return $numerodefichs;
  }
  else return -1;
}
else return -1;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>script</title>
</head>
<body>   
<?php
$pathcompleto = $path . $nombredir;
if (is_dir($pathcompleto)) {
$numfichs=cuentaficheros($pathcompleto);
if ($numfichs>0) {   
  $alea=rand(1,$numfichs);
  $dir=opendir($pathcompleto);
  while ($alea>0) {
  $nombrefich=readdir($dir);
  if (($nombrefich{0}==".")||(is_dir($pathcompleto . "/$nombrefich")))
    continue;
  $alea--;
  }

  print "<img src=\"/~daniel/$nombredir/" . $nombrefich . "\" />";
}
}
?>
<p>Contenido de la p&aacute;gina</p>
</body>
</html>
Última modificación: martes, 6 de agosto de 2013, 12:04