How to remove photos from public folder or protect to not be accessed by URL using Intervention image with Laravel?

Asked

Viewed 266 times

0

I am using the image Intervention is this all working, my doubt and I would like to remove the saved photos from the public folder not to be accessed by the URL or protect the access by the URL for safety sake would anyone know how to do ? That 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/
  • You can place a watermark on the image or restrict its access through the URL by uploading it to the Laravel Storage, however, I don’t know how the performance will be. , if you want the second option, you can follow this answer: http://stackoverflow.com/questions/30682421/how-to-protect-image-public-view-in-laravel-5

  • Thanks! I’ll try the second option

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 ) );

Note, however, that you will need to go through a specific route for loading/returning the images, and it is no longer possible to point directly to a public subtree.

By doing this you "gain" the possibility to treat the accesses to the images by permission levels, return resized according to the agent who made the request, etc.

  • Thank you for the answer ! I will try here

  • Sorry I’m new to Windows how can I change the Helper to the Storage Ademir folder? Thank you

  • Compare my example line with yours, I just changed the function call from public_path for storage_path

  • Thank you ! Ademir Mazer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.