Can you check the permission and make sure you can write to it? Also check your logs file if any errors happens when it wants to save the image.
Oct 6, 2018
3
Level 1
Problem saving images online,the image saving works on my local machine
What might be the problem with my code, here is a sample of my controller's code for saving data and image to database, the image saves in database but fails to save to the specified storage image path... public function store(Request $request) { $this->validate($request,[ 'title'=>'required', 'slide_images'=>'image|nullable|max:1999' ]);
//handle upload file
if($request->hasFile('gallery_image')){
//get file name with extension
$filenameWithExt=$request->file('gallery_image')->getClientOriginalName();
//get just a file name
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
//get just extension
$extension = $request ->file('gallery_image')->getClientOriginalExtension();
//file name to store
$fileNameToStore=$filename.'_'.time().'.'.$extension;
//upload image
$path = $request->file('gallery_image')->storeAs('/public/gallery_images',$fileNameToStore);
}else{
$fileNameToStore='noimage.jpg';
}
//create new post
$gallery=new Gallery;
$gallery->title=$request->input('title');
$gallery->gallery_image =$fileNameToStore;
$gallery->user_id=0;
$gallery->save();
return redirect('/gallery')->with('success','Post created Successfully');
}
Please or to participate in this conversation.