Home > Article > Backend Development > What should I do if php cannot use relative paths?
The solution to the problem that php cannot use relative paths: First create a PHP sample file; then place all script execution files in the root directory of the source file.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Let’s use test.php to demonstrate
Use test. PHP determines whether du.txt exists. We can clearly see that du.txt and test.php are under the same path
However. . .test.php
<?php $file = file_exists('du.txt');echo var_dump($file);?>Run results
Why does this happen when we are in the same directory? Woolen cloth?
It turns out that the folder opened with vscode is recognized as the source file root directory and all paths opened are relative to this path
<?php $file = file_exists('data/du.txt'); echo var_dump($file); ?>
The running result:
Summary:
It is best to place all script execution files in the root directory of the source file (the new folder in the picture), otherwise it will cause serious compatibility problems !
Recommended study: "PHP Video Tutorial"
The above is the detailed content of What should I do if php cannot use relative paths?. For more information, please follow other related articles on the PHP Chinese website!