Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-30-2010, 07:57 AM   PM User | #1
is_set
New to the CF scene

 
Join Date: May 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
is_set is an unknown quantity at this point
Arrow how to explore a directory with the php

hello,
today we will know how to know the content of any folder with the php with a simple code
first you should download this simple class

then we can use it for that
just include it
PHP Code:
require_once ('readDir.class.php'); 
and start new one
then you have to set the path of your folder
PHP Code:
if (!$dir->setPath$base_dir.'/example' )) {
    die(
$dir->error());

know if you want to make the system going on any sub folder just use
PHP Code:
$dir->readRecursive(true); 
and you can use the call back system in the class just like that
PHP Code:
// set a function to call when a new dir is read
if (!$dir->setEvent'readDir_dir''my_dir_function' )) { ;
    die(
$dir->error());

// set a function to call when a new file is read
if (!$dir->setEvent'readDir_file''my_file_function' )) {
    die(
$dir->error());

you can see the example:example.php
and you can make the system stoping at a specifice point just like that
PHP Code:
    if ($filename == 'secret_php_file.php') {
        echo 
'We found the file we are looking for. Stopping directory read.<br />';

        return -
1// return negative 1 to stop the reading of the directory
    

is_set is offline   Reply With Quote
Old 05-30-2010, 01:22 PM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,911
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
as of PHP5 PHP has built-in classes for this , see http://au.php.net/recursivedirectoryiterator
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 05-30-2010, 02:36 PM   PM User | #3
is_set
New to the CF scene

 
Join Date: May 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
is_set is an unknown quantity at this point
oh great this the first time i konw that
thank u
is_set is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:13 PM.


Advertisement
Log in to turn off these ads.