Anyway when you include files by script (not scpecifying the order in which u include them) check out class inheritage and class usage in files you include. Classes that are inherited must be included first.

        Andy


At 7:22 PM +0900 6/13/06, Dave M G wrote:
PHP List,

Up until now, in order to get all the functions and classes I need in my scripts, I have 
always made a file called "includes.php" that contains a series of include() 
statements for all of the files that I want to include. Then I just include that one file 
at the top of all my PHP scripts.

This system works okay, but I thought it would be better to have a consistent 
naming standard, and use some kind wild card or loop to include all the files I 
want. That way I can change, add, and remove files a little easier.

All the files I want to include end with either ".class", or with "_fns.php". ("fns" 
stands for "functions".)

It seems that wildcard characters are not supported in the include() function. 
Some experiments and a search on the web seem to confirm this.

So then I thought what I need to do is use the readdir() function somehow, and make an array of all 
files ending in ".class" or "_fns.php", and then make a while or foreach loop 
to include every required file.

I couldn't quite figure out how to do that, but in any case I wondered if 
running this loop at the start of every single PHP script might be unnecessary 
overhead. After all, the list of included files will only change when I work on 
the system. It's not going to vary at all based on any kind of user input or in 
standard usage of my web site.

What would be the recommended way of including files that will change as I work 
on the system? Do most people create a function to detect the included files, 
or do most people make a static list that they edit by hand?

--
Dave M G


Dave:

I group my includes per functionality, such as all dB operations (config, open, close, etc.) go into a db include folder (db_inc) and so on. I don't make large files, but rather small files limited to a specific operations. That works for me -- but, only you can figure out what works for you.

As for your code, try this:

<?php

        $file_path = $_SERVER['DOCUMENT_ROOT']; // or whatever directory you 
want
        $the_dir = opendir($file_path);

        while ($file = readdir($the_dir))
                {
if(eregi("(\.pdf|\.html|\.htm|\.php|\.txt)$", $file)) // check the files extension:
                        {
                        $html[] = $file;
                        }
                }

        closedir($the_dir);

        if($html == null)
                {
                die("No files in this directory!");
                }
                
        sort($html);
        foreach($html as $html => $value)
                {
                echo ("<br/> $value");
                }
?>


hth's

tedd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to