这是index.php
<?php
$file = './test.php';
$content = file_get_contents($file);
echo $content;
然后test.php中就一句话:this is a test
这两个文件位于同一级目录,我在浏览器中运行时,'this is a test'这句话会被正常打出来,而用命令行运行时却出现了警告,也没有输出'this is a test'.
错误如下:
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
然后我将$file改为了绝对路径
$file = 'G:/www/test.php';
命令行下就能输出'this is a test',为什么用相对路径在命令行下就出错了?我很困惑,是什么没有设置对吗?