我现在正在使用Laravel-5
,我刚刚创建了一个名为test(test.json)的JSON
文件。我的问题是:
- 我应该把我的JSON文件放在哪里?
- 如何使用
file_get_contents
并指向我想要的那个文件?
这是我尝试过的,但显然是错误的:
$string = file_get_contents("../json/test.json");
$json_file = json_decode($string, true);
非常感谢您的帮助!
我现在正在使用Laravel-5
,我刚刚创建了一个名为test(test.json)的JSON
文件。我的问题是:
file_get_contents
并指向我想要的那个文件?这是我尝试过的,但显然是错误的:
$string = file_get_contents("../json/test.json");
$json_file = json_decode($string, true);
非常感谢您的帮助!
你可以将它存储在Laravel的存储文件夹中:
$path = storage_path() . "/json/${filename}.json"; // ie: /var/www/laravel/app/storage/json/filename.json
$json = json_decode(file_get_contents($path), true);