File_get_contents () solution

Source: Internet
Author: User
File_get_contents () this is index. phpPHPcode & lt ;? Php $ file. test. php; $ contentfile_get_contents ($ file); echo $ content; then test. in php, the two thisisatest files are located in the same level Directory. when I run them in a browser, thisis file_get_contents ()
This is index. php.
PHP code
  
  

Then in test. php, there is one sentence: this is a test
These two files are located in the same level Directory. when I run the 'This is a test' statement in a browser, it will be normally typed out, but a warning will appear when I run the command line, no output 'This is a test '.
The error is as follows:
C: \ Users \ hahaliu> php G: \ www \ index. php
PHP Warning: file_get_contents (test. php): failed to open stream: No such file
Or directory in G: \ www \ index. php on line 3

Warning: file_get_contents (test. php): failed to open stream: No such file or di
Rectory in G: \ www \ index. php on line 3
Then I changed $ file to an absolute path.
$ File = 'G:/www/test. php ';
The command line can output 'This is a test'. why is an error in the command line with a relative path? I am very confused. Is it true that nothing is set?



------ Solution --------------------
Without considering the parameter de_path in php. ini:

Browsing through a browser, that is, when browsing as a web server, the directory where files run is configured based on the web server.

The command line is based on the path of the system environment.

The following two outputs show the differences.
PHP code
echo getcwd();echo ini_get('include_path');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.