Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/10/2010, 03:21
uniom
 
Fecha de Ingreso: octubre-2010
Mensajes: 4
Antigüedad: 13 años, 7 meses
Puntos: 0
imagenes en php

Hola a todos y gracias por adelantado. Soy nuevo en esto y tengo un problema. Quisiera hacer una funcion que me contara los archivos de un directorio, y luego aleatoriamente me mostrase una foto. He hecho esto pero no me muestra ninguna, si alguien sabe porque por favor me lo diga.

<?php
$path = "/home/hector/";
$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=\"/home/hector/$nombredir/" . $nombrefich . "\" />";
}
}
?>
<p>Contenido de la p&aacute;gina</p>
</body>
</html>


Saludos