Please go back to your original question and format your code by putting 3 backticks ``` on a line before and after each code block
Encryp Image to later read in view
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.
Check https://stefanzweifel.io/posts/how-to-encrypt-file-uploads-with-laravel/
as for the filename, just give it a uuid and store it in the database. I don't see any point in keeping the original name, although you might want the file extension. Certainly no point in encrypting the filename.
Please or to participate in this conversation.