• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help on directory helper

#1
[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

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

#3
[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

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

#5
[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

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

#7
[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

#8
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.