How do I remove the photos from the public folder or protect them from being accessed by the URL using Intervention image with Laravel?

0

I'm using the intervention image is this all working, my doubt and would like to remove the saved photos from the public folder so as not to be accessed by the URL or protect access by the URL for security reasons would anyone know how to do it? This is my Code ::

public function update_avatar(Request $request){
        // Controle do upload do usuário do avatar
        if($request->hasFile('avatar')){
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)>resize(300, 300)>save( public_path('/uploads/avatars/' . $filename ) );
            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();
        }
        return  view('profile', array('user' => Auth::user()) );
    }/fim da function para fazer upload de imagens/
    
asked by anonymous 18.05.2017 / 04:10

1 answer

0

Change the line where you save the image, change the helper to point to the storage directory and not to the public folder:

Image::make($avatar)>resize(300, 300)>save( storage_path('/uploads/avatars/' . $filename ) );

Please note, however, that you will need to go through a specific upload / return route for images, and it is no longer possible to point directly to a public subtree.

By doing this you "gain" the ability to treat access to images by permission levels, return resized according to the requesting agent, etc.

    
22.05.2017 / 20:45