[Sussex] PHP Question: How to include all files in a directory
Gareth Ablett
Gareth.Ablett at itpserve.co.uk
Mon Feb 14 10:29:50 UTC 2005
> -----Original Message-----
> From: sussex-bounces at mailman.lug.org.uk
[mailto:sussex-bounces at mailman.lug.org.uk] On Behalf Of Mark
> Harrison (Groups)
> Sent: 13 February 2005 10:14 pm
> To: LUG email list for the Sussex Counties
> Subject: Re: [Sussex] PHP Question: How to include all files in a
directory
>
> Steve Dobson wrote:
>
> >Matt
> >
> >On Sun, Feb 13, 2005 at 07:36:22PM +0000, Matthew Macdonald-Wallace
wrote:
> >
> >
> >>On Sun, 13 Feb 2005 13:05:14 +0000 Steve Dobson <steve at dobson.org>
wrote:
> >>
> >>
> >>>I am developing a little PHP system and I want to make it easy
> >>>for users/SysAdmins to add their own functions PHP extension
routes.
> >>>
> >>>Is there any way of "require_once('lib/functions/*.php');" so that
> >>>all the user has to do is install his functions in the
lib/functions
> >>>dir and the system will automatically pick them up.
> >>>
> >>>
> >>Steve,
> >>
> >>You could create a file called include.php and have it do the
following:
> >>
> >>foreach($fileList)
> >>{
> >> require_once("filename")
> >>}
> >>
> >>and then just:
> >>
> >>require_once("include.php");
> >>
> >>bear in mind this is pseudo-code and could be extremely server
intensive,
> >>but it is one way I can think of!
> >>
> >>
> >
> >But where do I get $fileList from?
> >
> >Steve
> >
> >
> system ("ls /.../lib/functions/*.php > ./listfilename")
> $fp = fopen("./listfilename")
>
> ?
>
> M.
man that's a very messy method of getting file list.
if ( $myfiles = scandir($dir) )
{
for( $x=0; $x<count(myfiles)-1; $x++)
{
if ( substr($myfiles[$x],13,3) == 'php')
{
require_once $myfiles[$x];
}
}
}
else
{
echo "error looking at {$dir} or no files found";
}
Gareth Ablett
Systems Developer
ITP Services Ltd.
http://www.itpserve.co.uk/
------------------------------------------------------------------------
The recipient acknowledges that ITP Services Ltd is unable to control
the content of information in transmitting mail and attachments over the
Internet. ITP Services Ltd makes no warranty as to the quality,
accuracy and content of information contained in or with this message.
In
reading, opening or receiving this e-mail the recipient accepts full
responsibility for its content and attachments.
More information about the Sussex
mailing list