【发布时间】:2018-01-03 08:10:44
【问题描述】:
所以我有这个 Laravel 项目,我想将一个数组导出到一个 json 文件以供以后使用。我对存储文件夹的权限是 777,但是当我这样做时
$line=[
'key1'=>'value1',
];
file_put_contents("storage/app/test.json",json_encode($line));
我也试过
$line=[
'key1'=>'value1',
];
file_put_contents($_SERVER['DOCUMENT_ROOT']."/storage/app/test.json",json_encode($line));
在这两种情况下(加上更多)我都会收到这个错误
file_put_contents(storage/app/test.json): failed to open stream: No such file or directory
你知道为什么会这样吗?
编辑:文件夹存在
【问题讨论】:
-
storage中有文件夹app吗? -
当然,我也有文件,但是如果文件不存在,我希望它自动创建文件
标签: php json laravel file fopen