I'm trying to show content of text file (1.txt) by using file_get_contents() function, and of course I'm working with yii2 framework.
if there is simpler function in yii2 please suggest me.
Here is my code in controller:
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', [
]
);
}
I get this error in result.
file_get_contents(/test/files/upload/1.txt): failed to open stream: No such file or directory
The file is exist in the path, but I don't know why I get this error.
These answers didn't help me well.