Welcome Guest, Not a member yet? Register   Sign In
Reading/Parsing Directories and Files
#1

[eluser]pgsjoe[/eluser]
Hate to rely on the message board, so I apologize. Here's the deal though. I have a directory called 'Photos' inside of photos are 'Category1', 'Category2', etc.

First thing I want to do is get an array of the directories inside 'Photos' so I can put those into a dropdown list. Second, I want to be able to get a list of files from inside the category chosen, to put inside their own dropdown list.

Idea being, the client would create directories and upload photos using an FTP client. Then, associate those files to Title, Alt tags and Dates using a CI form. The form would allow the person to enter previous info, then attach the file information (directory & filename) to it and upload it to the database.

The client is a photographer, and since they have access to an FTP I don't really see a form uploader as being entirely necessary. So, I thought this might be the easiest way. So any help with getting it to work, or suggestions on a better, hopefully not TOO complicate way would be awesome.

This is the first full client project I'm trying out CI on and am damn excited to be jumping in. Hence, sitting home on a Saturday night coding. Thanks in advance.
#2

[eluser]Elliot Haughin[/eluser]
Try something like this for size:

Code:
function read_files($dir)
{
$handle = opendir($dir); // your directory here
$files = array();
if ($handle)
{
    while ( false !== ($file = readdir($handle)) )
    {
        // make sure we don't map silly dirs like .svn, or . or ..
        
        if (substr($file, 0, 1) != ".")
        {
            $files[$file] = array();
                        if (is_dir($dir.'/'.$file) $files[$file] = read_files($dir.'/'.$file);
        }
    }
}
return $files;
}

This should dynamically traverse an entire structure and return an array accordingly... like:

Code:
array(
     'directory1' => array('directory2' => array('file1', 'file2'), 'file3')
);

Hope this helps.
#3

[eluser]Référencement Google[/eluser]
http://ellislab.com/codeigniter/user-gui...elper.html
Isn't that what you're looking for?
#4

[eluser]pgsjoe[/eluser]
I was thinking it had to be something a bit more complex, but, damn. Looks like CodeIgnitor pulls through. So I've almost got it where I need it, guess now I just need to go back to some basic array help and some dynamic functionality.

I think I read something before, might have been PEAR, that was a form variable with actions attached to it. Checked back in the form helper here and didn't see it. And I swear, I'm a learner, not a copier. I was wondering if someone could provide help with going back and forth to the function once inside.

Here's what I would really want to happen. Person has the form. There are two dropdowns in the form, 'directory' and 'file'. One active select option for the directory, the other a grayed out select option filename. When they select the directory they want, the 'file' select option would become active and filled with a list of files from that directory.

I know there's a bit of Javascript involved with it too, but any direction or help you could provide with this would be, oh so appreciated. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB