emfpc
1 month ago
198
10
Laravel

Encryp Image to later read in view

Posted 1 month ago by emfpc

Currently, using a form, I let the user upload a picture. This picture is later store in the Database. I'm trying to encrypt de data that goes to the Database plus the image. In my controller i doing this:

$user->identification = Crypt::encrypt($request->input('identification'));
if($img = $request->file('identification')){
                $img->storeAs('upload/images/Identification Files', "Ticket #".$ticket->ticket_number."_".$completname.".".$img->getClientOriginalExtension());
}

In the database it show the name of the identification field is encrypted but the image is not.

Try this one instead:

$user->identification = Crypt::encrypt($request->input('identification'));
$img = Crypt::encrypt($request->file('identification')->get());
Storage::put('upload/images/Identification Files/'.'Ticket#'.$ticket->ticket_number.'_'.'IdentificationOf_'.$completname,$img);

with this i was able to change the image but in order to read it on a view need to put the name of the file by hand in order to read it: *In User Controller @index:

$encryptedContent = Storage::get('upload/images/Identification Files/*NameOfTheFile');
$decryptedContent = decrypt($encryptedContent);
return view('photo', compact('encryptedContent', 'decryptedContent'));

*in the Photo view:

<img src="data:image/png;base64,{!! base64_encode($decryptedContent) !!}" alt="" />

The last one show the image but i'm trying to get the image to display when i looking for a particular user without inputing the name of the file is Storage::get.

Help will be appreciate. If is not easy to understand please let me know.

Please sign in or create an account to participate in this conversation.