<?php
 
	/*
	 * script  : randImg.php
	 * version : 1.0
	 * author  : enrique@barbeito.org
	 * date    : vie feb 25 12:32:21 CET 2004
	 * 
	 * Requirements:
	 *  - PHP >= 3.x
	 *
	 * Description:
	 *  Un simple script en PHP para cargar imagenes
	 *  aleatoriamente. Requiere que las imagenes a
	 *  rotar se encuentren en un directorio separado
	 *
	 * */
 
	define("kRUTA","../img/random");/* directorio donde  se  encuentran
					 * las imagenes que rotaran. Si vas
					 * a utilizar este script cambia la
					 * ruta    por   la   tuya   propia */
 
	/*           *
	 * funciones *
	 * --------- */
 
	function fLeeImg ()
	{
		// abrimos el directorio
		$workDir = opendir(kRUTA);
 
		// recogemos las imagenes y armamos un vector
		while ($fichero = readdir($workDir))
		{
			if (($fichero != ".") && ($fichero != ".."))
				$imagenes[]=$fichero;	
		}
 
		// cerramos el directorio
		closedir($workDir);
 
		return($imagenes);
	}
 
	function fAlazar ($array)
	{
		$numImg = count($array); // numero total de imagenes
		$i = rand(0,$numImg-1);  // intervalo [1..$numImg]
		$imagen = $array[$i];    // imagen aleatoria
 
		echo "<img src=\"".kRUTA.'/'."$imagen\" alt=\"imagen aleatoria\" border=\"0\" />";
	}
 
	// ** END ** //
 
	/*                    *
	 * programa principal *
	 * ------------------ */
 
	$imgs = fLeeImg(); // definimos un vector de imagenes
	fAlazar($imgs);    // devolvemos una imagen aleatoria
 
	// ** END ** //
 
?>
 
codigo/php/randimg.txt · Última modificación: 2006/12/08 22:39 (editor externo)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki