PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon May 29, 2017 2:42 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Wed Jun 27, 2007 6:19 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
The function returns an associative array. Iterate through it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 7:07 am 
Offline
Forum Contributor

Joined: Wed Jun 13, 2007 5:07 am
Posts: 109
i am very new to PHP Feyd so need your help in doing the above.

Hope you would help!

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 7:11 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
Your code will likely need foreach and is_array() along with arrays. I generally won't procure code until I see enough effort on your part.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 7:44 am 
Offline
Forum Contributor

Joined: Wed Jun 13, 2007 5:07 am
Posts: 109
i browsed a lot on that but in vain.. :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 9:32 am 
Offline
Forum Regular
User avatar

Joined: Wed Jul 30, 2003 3:29 am
Posts: 875
Location: Sweden
dream2rule wrote:
i browsed a lot on that but in vain.. :(

I'd recommend checking out some books or online tutorials/guides for PHP basics if the manual didn't help you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 7:05 pm 
Offline
Forum Newbie

Joined: Wed May 23, 2007 7:12 am
Posts: 3
streamkid wrote:
hello, my first post :D

i was looking for a directory tree to use it online, but i didn't find any implementation that would also print a link to the file
so i made one :)

you can see it here:
http://www.streamkid.de/~alex/?cat=stuff

Syntax: [ Download ] [ Hide ]
 
/* you call the function like this:
$img = array ('images');
ldir('images/', 0, 0, $img, 'images');
this will print the contents of directory images */

        function ldir($path, $level, $m, $struct, $abs) {
                $ignore = array ('cgi-bin', '.', '..', '.htaccess', '.t3hdirectives');
                $dh = @opendir($path);
                while (false !== ($file = readdir($dh))) {
                        if (!in_array($file, $ignore)) {
                                $spaces = str_repeat(' ', ($level*4));
                                $struct[$level] = $abs;
                                $url = '';
                                if ($level > 0) {
                                        for ($i = 0; $i <= $level; $i += 1) {
                                                $url .= $struct[$i];
                                                $url .= '/';
                                            }
                                        $url .= $file;
                                    }
                                else {
                                        $url .= $abs;
                                        $url .= '/';
                                        $url .= $file;
                                    }
                                if (is_dir("$path/$file")) {
                                        echo "<a title="This is a directory. Nothing to link to.">$spaces $file</a>&nbsp;<i>(dir)</i><br/>";
                                        $dir .= '/';
                                        $dir .= $file;
                                        ldir ("$path/$file", ($level + 1), $m, $struct, $file);
                                    }
                                else {
                                        switch ($m) {
                                                case 0: echo "<a href="?cat=stuff&amp;img=$url">$spaces $file</a><br/>"; break;
                                                case 1: echo "<a href="$url">$spaces $file</a><br/>";             break;
                                                case 2: echo "<a href="$url">$spaces $file</a><br/>";                break;
                                            }
                                    }
                            }
                    }
                closedir($dh);
            }
/* you can completely delete $m and the switch statement, i just used it because depending on the type the url differs */
 


i just started learning php, so your comments on the code are more than welcome :)


Watching traffic on my site, I see a lot of people coming from this thread to my site to see the listing script in action. I want to make an upate:
An updated version of the code can be found here:
http://streamkid.net/blog/programming/5 ... 0/12/2007/
and you can see the script in action here:
http://streamkid.net/~streamkid/

Thanks for the interest. :-)


Last edited by Weirdan on Sat May 03, 2008 7:36 am, edited 1 time in total.
php tags


Top
 Profile  
 
PostPosted: Thu May 01, 2008 8:18 am 
Offline
Forum Newbie

Joined: Mon Mar 17, 2008 4:55 am
Posts: 4
This is a very nice function.I think your iterative solution is very elegant!

-----------------
Gayathri


Top
 Profile  
 
PostPosted: Mon Sep 20, 2010 1:36 am 
Offline
Forum Newbie

Joined: Mon Sep 20, 2010 1:20 am
Posts: 12
Oooooh, great guy. that's what i exactly need in my this project!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group