Karuku_001's avatar

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');
}
0 likes
3 replies
AR's avatar

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.

1 like
Sergiu17's avatar

What logs are saying? Do you have permissions to store files in that folder?

AR's avatar

@Sergiu17 Does the image gets stored in another path or it does not store it at all?

Also check your logs file and see if there is any errors there. The file is located at /storage/logs/laravel.log. then you can trace what time what error has happened.

Let us know what you find out.

Please or to participate in this conversation.