Bueno primero que nada Saludos, hece algo que no merodeaba por la web fuera de entrar al IRC, nada.
Queria mencionar, preguntar si es possible leer el contenido de un directorio y reproducer el contenido desde una function de usuario?
Me explico, eg. Tengo este script;
<?php
function ur_function($path){
$hdl = (file_exists($path) && is_dir($path))? opendir($path): die();
while(false != ($data = readdir($hdl))){
if($data != "." && $data != ".."){
$file = $data;
}
}
closedir($path);
return($file);
}
$list = ur_function("./public/img/")
echo($list);
?>
Tengo esta function pero al invocarla solo me debuelve el ultimo archive del derictorio a administrar.
Queria saber si esto de alguna forma es possible? creando algun typo de cadena/array nose?
Gracias de antemano!
Agregando los archivos a un arreglo y luego retornando el arreglo quedaría así:
<?php
function ur_function($path){
$hdl = (file_exists($path) && is_dir($path))? opendir($path): die();
$files = array();
while(false != ($data = readdir($hdl))){
if($data != "." && $data != ".."){
$file = $data;
$files[] = $file; // agrega al arreglo el archivo
}
}
closedir($hdl);
return $files;
}
$list = ur_function("./public/img/") ;
foreach ($list as $value ) {
echo $value . "<br>";
}
?>