I’ve been writing:
include('a.php')
include('b.php')
etc. in my script to include to use functions a() and b(). It gets pretty tedious. Is there a way to set a path of a directory and have multiple files there be accessible by a script?
-
I tried this in my script:
set_include_path('.;C:\xampp\htdocs\myfunctionfolder'); -
And I set an environmental variable PATH to have this older in there.
-
I also in modified php.ini to include
include_path = ".;\xampp\php\PEAR;\xampp\htdocs\myfunctionfolder"
If I have many files in there, how do I access these files without having to include each individually? Setting the environmental variable definitely works in the command prompt.
Do I need to do something else for .php files to be accessible collectively under a directory?
Common practice is to have a “common.php” or “includes.php” file that includes the
include/include_oncecalls (for the sake of simplicity). e.g.Then includes.php contains:
Then in any script it’s a matter of including the
includes.phpfile.However, to answer your original question, you can only include one file at a time, per call. You can use something like
opendirandreaddirto iterate over all files in a specific directory and include them as found (automated so-to-speak) or write out each include yourself based on the files you’re creating.Also, all setting the include path does is set a directory to look in when an
includecall is made. It’s not a directory where the files should automatically be loaded (which is the impression I get from your post).