Home  >  Article  >  Backend Development  >  What should I do if php cannot use relative paths?

What should I do if php cannot use relative paths?

藏色散人
藏色散人Original
2021-05-13 09:29:141951browse

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.

What should I do if php cannot use relative paths?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

Relative path identification problem in php (vscode)

What should I do if php cannot use relative paths?
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(&#39;du.txt&#39;);echo var_dump($file);?>

Run results
What should I do if php cannot use relative paths?

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

Let’s follow Change the code

<?php $file = file_exists(&#39;data/du.txt&#39;);
echo var_dump($file);
?>

The running result:

What should I do if php cannot use relative paths?

can run normally!

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 !

What should I do if php cannot use relative paths?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn