file_put_contents doesn't work with json laravel & php -
i tried push item json
file when call file_put_contents("file.json",$data)
doesn't work , page shutdown.
here's controller code.
public function addjson() { $titulo = input::get('title'); $name = input::file('image')->getclientoriginalname(); $arr = json_decode(file_get_contents("js/data.json"), true); array_push($arr['galerias'], array('id' => count($arr['galerias'])+1, 'name' => $name, 'img' => 'galeria/'.$name)); $arr2 = $arr['galerias']; $arr = json_encode($arr); echo $arr; file_put_contents('js/data.json', $arr); return view('main.prueba')->with('name',$arr2); }
and here json
file.
{ "galerias": [ { "id": 1, "name": "fiesta privada", "img": "galeria/fp.jpg" }, { "id": 2, "name": "fiesta privada", "img": "galeria/fp2.jpg" }, { "id": 3, "name": "fiesta privada", "img": "galeria/fp3.jpg" }, { "id": 4, "name": "fiesta privada", "img": "galeria/fp4.jpg" }, { "id": 5, "name": "fiesta privada", "img": "galeria/fp5.jpg" }, { "id": 6, "name": "fiesta privada", "img": "galeria/fp6.jpg" }, { "id": 7, "name": "los kjarkas", "img": "galeria/los_kjarkas.jpg" }, { "id": 8, "name": "palmenia pizarro", "img": "galeria/palmenia_pizarro.jpg" }, { "id": 9, "name": "palmenia pizarro", "img": "galeria/palmenia_pizarro_2.jpg" }, { "id": 10, "name": "palmenia pizarro", "img": "galeria/palmenia_pizarro_3.jpg" } ] }
heeeelp me pls :c
it permission problem
is directory /js
chmoded 777? php won't allow access directories if don't have enough permission. don't know blank errors though.
try see if has enough permissions, if not, set 777 , try it.
Comments
Post a Comment