list files in a directory with codeigniter

0

I can not list a directory in codeiniter, I just need the names of the files, before I did it like this:

setlocale(LC_ALL,"es_ES");
    $path="servicios/"; //directorio a listar
    $directorio=dir($path);

$pn= array();//pila de nombres
$pf= array();//pila de fechas
$pt= array();//pila de tamaNos

while ($archivo = $directorio->read()){

$archivo1="servicios/".$archivo;

if(file_exists($archivo1)){
if(($archivo!='index.php')&&($archivo!='.')&&($archivo!='..')){
array_push($pn, $archivo);
array_push($pf, date("d F Y H:i", filemtime($archivo1)));
array_push($pt, filesize($archivo1));
}
}
else
    {
        echo 'no existe' ;
        //var_dump($archivo);
    }
}
$directorio->close();

array_multisort($pn,SORT_DESC,$pf,$pt);
for($i=0; $i<count($pn); $i++){
    echo "<a href='servicios/".$pn[$i]."'>".$pn[$i]."</a>";
    setlocale(LC_ALL,"es_ES");
    echo " <b>fecha:</b>".$pf[$i];
//echo '<a href="servicios/'.$pn[$i].'">'.$pn[$i]."</a><b>fecha:</b>".$pf[$i];
printf(" <b>peso:</b>%1.3fKb<br>\n",$pt[$i]/1000);
}

Then I tried the codeigniter function:

$map = directory_map('./mydirectory/');

to the directory it can be in the root and also in the same folder of the view to try but it always shows null

    
asked by esteban cuezzo 22.12.2018 в 01:05
source

1 answer

0

In order for this function to be carried out, you must import the helper:

$this->load->helper('directory');

The variable that will become an array is created:

$map = directory_map('./mydirectory/');

And going through that arrangement with a foreach you can see its content and you'll have something like this:

Array (
    [libraries] => Array
        (
            [0] => benchmark.html
            [1] => config.html
            ["database/"] => Array
                    (
                            [0] => query_builder.html
                            [1] => binds.html
                            [2] => configuration.html
                            [3] => connecting.html
                            [4] => examples.html
                            [5] => fields.html
                            [6] => index.html
                            [7] => queries.html
                    )
            [2] => email.html
            [3] => file_uploading.html
            [4] => image_lib.html
            [5] => input.html
            [6] => language.html
            [7] => loader.html
            [8] => pagination.html
            [9] => uri.html
    )

For more information you can go to the documentation of Codeigniter with respect to Directory Helper .

    
answered by 22.12.2018 в 01:42