Path problem in php and the use of set_include_path

  • 2020-12-22 17:36:16
  • OfStack

first:

Common paths in php

Current file path: D:\phpweb\php_example\ include_path.php
 
1.dirname(__FILE__); // The output D:\phpweb\php_example 
2.$_SERVER['SCRIPT_FILENAME']; // The output D:/phpweb/php_example/include_path.php 

second:

The set_include_path php

In php, include files, when containing paths that are neither relative nor absolute (e.g. include(" example.php ")), look for the directory include_path set and then look for the current directory, which is why many sources mention that include("./ example.php ") is more efficient than include(" example.php ").

Methods:

1.ini_set("include_path", "/usr/lib/pear"); // All versions
2.set_include_path("/usr/lib/pear"); //version > =4.3.0
You can add a directory to an existing directory in the following way
 
<?php 
$path = '/usr/lib/pear'; 
set_include_path(get_include_path() . PATH_SEPARATOR . $path);// After setting include_path A similar /usr/lib/function;/usr/lib/pear 
?> 

Related articles: