CodeIgniter Forums
help on directory helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: help on directory helper (/thread-12094.html)



help on directory helper - El Forum - 10-06-2008

[eluser]syntaxerror[/eluser]
hi,
i need help.
its my first time in using codeigniter.
i need a script that reads files in a folder into an array.
i think the directory helper can do it.
but i dont know how to use it.
in my controller
i made a function
Code:
function index()
    {
        $data['title'] = "DS Validator";
        $data['header'] = "DS Validator";
        $map = directory_map('C:/xampp/htdocs/AccmaRoster/', TRUE);
        $this->load->view('front_view', $data);
        
    }
and in my view
Code:
<?php foreach($map as $file): ?>
            <li>
                <ol>&lt;?php echo $file; ?&gt;</ol>
            </li>
&lt;?php endforeach; ?&gt;

but there is an error
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: map

Filename: views/front_view.php

Line Number: 26
Code:
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/front_view.php

Line Number: 29

please help

thanks


help on directory helper - El Forum - 10-06-2008

[eluser]xwero[/eluser]
You haven't added map to the data array.


help on directory helper - El Forum - 10-06-2008

[eluser]syntaxerror[/eluser]
ok
Code:
$data['map']= directory_map('C:/xampp/htdocs/AccmaRoster/', TRUE);
but can i use this? is this right?
Code:
$data['map']= directory_map('C:/xampp/htdocs/$_POST['directory']/', TRUE);

thanks


help on directory helper - El Forum - 10-06-2008

[eluser]Yash[/eluser]
Code:
$data['map'] = directory_map('C:/xampp/htdocs/AccmaRoster/', TRUE); //change this line



help on directory helper - El Forum - 10-06-2008

[eluser]syntaxerror[/eluser]
Code:
$data['map'] = directory_map('C:/xampp/htdocs/AccmaRoster/', TRUE); //change this line
why? this is working. but i have to input the folder name manually, and the program will list down all files in that folder


help on directory helper - El Forum - 10-06-2008

[eluser]Yash[/eluser]
use base_url() function and don't use hard coding


help on directory helper - El Forum - 10-06-2008

[eluser]syntaxerror[/eluser]
the user has to enter the directory where he wants to view the list of files
Code:
$data['map'] = directory_map('C:/xampp/htdocs/AccmaRoster/'(the directory must be user entry), TRUE);
how to change the hardcoded directory to $_POST?

thanks


help on directory helper - El Forum - 10-06-2008

[eluser]xwero[/eluser]
adding the post value without validation isn't a good idea. But when you validated the input you can add the $_POST value to the function.