include php dir

Solutions on MaxInterview for include php dir by the best coders in the world

showing results for - "include php dir "
Vincenzo
01 Apr 2019
1PHP scripts run relative to the current path (result of getcwd()), 
2not to the path of their own file. 
3Using __DIR__ forces the include to happen relative to their own path.
4CORRECT: in file2.php: include (__DIR__ . "/file3.php");
5To demonstrate:
6- file1.php
7- dir/
8   - file2.php
9   - file3.php
10If file2.php includes file3.php like this: include `file3.php`.
11It will work fine if you call file2.php directly. 
12However, if file1.php includes file2.php, 
13the current directory (getcwd()), will be wrong for file2.php, 
14so file3.php cannot be included.
Angel
13 Feb 2017
1<?php
2include __DIR__ . "/worker_2.php";