programing

Laravel5 Json 파일 내용 가져오기

fastcode 2023. 3. 1. 13:48
반응형

Laravel5 Json 파일 내용 가져오기

사용하고 있다Laravel-5지금 바로 제가 만든 건JSONtest(test.json)라는 파일입니다.질문입니다.

  1. JSON 파일은 어디에 두면 되나요?
  2. 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); 

언급URL : https://stackoverflow.com/questions/35374699/laravel5-json-get-file-contents

반응형