0

I need user image content to be encrypted and store into database and then decrypt before display .My code in controller to encrypt,

public function savePicture(Request $request)
{
     $file = Input::file('pic');
     $img = Image::make($file);
     Response::make($img->encode('jpeg'));

     $picture = new Picture;
     $picture->name = $request->get('name');
     $picture->pic = $img;
      $picture->pic=Crypt::encrypt(file_get_contents($file));
      //dd($picture);
     $picture->save();

}

When I run this code I got the error PDOStatement::execute(): MySQL server has gone away (SQL: insert into pictures (name, pic, updated_at, created_at)... How do I solve solve this?

matronator
  • 465
  • 6
  • 13
usertest
  • 399
  • 2
  • 14
  • 31
  • 1
    Why does it need to be encrypted? And why store it in the database? – tkausl Nov 01 '17 at 09:34
  • I need my images to be secure what else 'll be – usertest Nov 01 '17 at 09:37
  • Is there anyway to do this or it(encrypt & decrypt) doesn't need? – usertest Nov 01 '17 at 09:55
  • @saranya Please refer to this : [Using PHP to encrypt image for storage in MySQL BLOB then decrypt and print](https://stackoverflow.com/questions/46396925/using-php-to-encrypt-image-for-storage-in-mysql-blob-then-decrypt-and-print). See if it can help. – Parantap Parashar Nov 01 '17 at 10:01

0 Answers0