What should I do if php cannot use relative paths?

藏色散人
Release: 2023-03-09 16:48:01
Original
1969 people have browsed it

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);?>
Copy after login

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);
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!