Re: include whole directories?
| From: | Erica Douglass | Date: | Sat, 28 Apr 2001 01:44:49 +0000 |
| Subject: | Re: include whole directories? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-50714@lists.php.net to get a copy of this message | ||
Sure. Use an array, as suggested in the example on the include manual page,
but put all files in a specific directory in that array. To do that, use
code like the following:
# load files into array
# assign $directory to your variable, or replace $directory in the below
line with the directory you want.
$handle=opendir($directory);
while ($file = readdir($handle)) { # read all files in dir
if ($file != ".." && $file != ".") {
$files_to_include[count($files_to_include)] = $file; # cram them files
into array ;)
};
};
#clean up and sort
closedir($handle);
if (is_array($files_to_include)) {
while (list ($key, $val) = each ($files_to_include)) {
include $files[$i];
};
};
I modified some previous code to work for what you want, so my apologies if
there are missing curly braces or the like.
Hope this helps,
Erica
"andrew" <andrew@salamander.net> wrote in message
news:200104280007.f3S077608569@chmls20.mediaone.net...
>
>
> Is there any way to include whole directories?
> I have my function declarations in many small, easily maintainable
> files, but it's a pain to include/require them all individually...I
> would like to just split them into directories by common purpose, e.g
>
> functions/auth
> functions/content
> functions/modules
>
> and then include a directory at once - any ideas?
>
> cheers!
> andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>