I tried everything to push item into json
file but when call
file_put_contents("file.json",$data)
doesn't work and the page shutdown.
Here's my 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 is the 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 could be a permission problem
Is the directory /js
chmoded to 777? sometimes php won't allow you to access directories if they don't have enough permission. I don't know about blank errors though.
Try to see if it has enough permissions, if not, then set it to 777 and try it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With