PHP, How to set include path

Viewed 71424

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?

  1. I tried this in my script:

    set_include_path('.;C:\xampp\htdocs\myfunctionfolder');
    
  2. And I set an environmental variable PATH to have this older in there.

  3. 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?

7 Answers
include __DIR__ . '/../folder1/folder2/folder3/Target.php';
include __DIR__ . '/../folder1/folder2/Target.php';

It helps you go to any path.

Download latest PHP zip and extract to C drive then download composer and install it, during installation it ask for PHP path so just select extracted PHP path.

As follow below step.

  1. Go to Computer.

  2. Select Advance System Settings.

  3. From system properties select Environmental Varaibles.
  4. In Environmental Varaibles add Path in User Variable for PCNAME
  5. In Environmental Varaibles add Path in System Variables.
  6. Hit OK.
  7. Restart PC.
  8. Win + R type cmd.
  9. type command php -v.
  10. Vola you good to go.

PHP http://php.net/downloads.php

Composer https://getcomposer.org/download/

Related