我试图通过使用file_get_contents()函数显示文本文件的内容(1.txt),当然我正在使用yii2框架。错误未能打开流:file_get_contents()中没有这样的文件或目录()
如果在yii2中有更简单的功能,请给我建议。
这是我在控制器代码:
public function actionRandom() {
$fileContent = file_get_contents(Yii::$app->request->baseUrl.'/files/upload/1.txt',true);
echo Json::encode($fileContent);
Yii::app()->end();
return $this->render('random', [
]
);
}
我在结果得到这个错误。
file_get_contents(/test/files/upload/1.txt): failed to open stream: No such file or directory
该文件存在于路径中,但我不知道为什么会出现此错误。
这些答案对我没有帮助。
添加http://到开始的file_get_contents部分。 – Farkie
可能重复的[无法打开流:没有这样的文件或目录](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) –