php - Working with encrypted files in Laravel (how to download decrypted file) -


in webapp, users can upload files. before being saved , stored, contents of file encrypted using this:

crypt::encrypt(file_get_contents($file->getrealpath())); 

i use file system comes laravel move file

storage::put($filepath, $encryptedfile); 

i have table store information each file columns such as:

  • id
  • file_path
  • file_name
  • original_name (includes extension)

now want user able download encrypted file. however, i'm having trouble decrypting file , returning user. in file downloads response section of laravel documentation, suggests this:

return response()->download($pathtofile, $name, $headers); 

it wants file path fine, @ point can decrypt file contents readable?

i seem able this:

$encryptedcontents = storage::get($filerecord->file_path); $decryptedcontents = crypt::decrypt($encryptedcontents); 

... don't know how return download specified file name.

you manually create response so:

$encryptedcontents = storage::get($filerecord->file_path); $decryptedcontents = crypt::decrypt($encryptedcontents);  return response()->make($decryptedcontents, 200, array(     'content-type' => (new finfo(fileinfo_mime))->buffer($decryptedcontents),     'content-disposition' => 'attachment; filename="' . pathinfo($filerecord->file_path, pathinfo_basename) . '"' )); 

you can check out laravel api more info on parameters of make method are. pathinfo function used extract filename path sends correct filename response.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -