【发布时间】:2016-12-20 21:08:43
【问题描述】:
我正在尝试使用 file_get_contents() 函数显示文本文件 (1.txt) 的内容,当然我正在使用 yii2 框架。
如果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 部分的开头。
标签: php yii2 yii2-advanced-app