In my webapp, users can upload files. Before saving and saving the contents of the file are encrypted using the following:
Crypt::encrypt(file_get_contents($file->getRealPath()));
Then I use the file system that comes with Laravel to move the file
Storage::put($filePath, $encryptedFile);
I have a table to store information about each file with columns such as:
- ID
- file_path
- file name
- original_name (includes extension)
Now I want the user to be able to download this encrypted file. However, I had problems decrypting the file and returning it to the user. The section on the answer file in the Laravel documentation files suggests doing this:
return response()->download($pathToFile, $name, $headers);
He wants the file path to be perfect, but at what point can I decrypt the contents of the file so that it is really readable?
I really can do this:
$encryptedContents = Storage::get($fileRecord->file_path); $decryptedContents = Crypt::decrypt($encryptedContents);
... but I do not know how to return it as a download with the specified file name.
php file-upload encryption laravel laravel-5
Marcel Jan 6 '16 at 1:16 2016-01-06 01:16
source share