0

I am new in laravel, try to encrypt the uploaded file. Here is my controller:

if ($file != null && !empty($file)) 
{
   $userfile = DNEUser::find($lastUserId);
   $user_store_pic = $request->file('user_store_pic');
   $fileContent = $user_store_pic->get();
   $encryptedContent = encrypt($fileContent);
   $s3 = \Storage::disk('uploads');
   //$array=explode(" ",$encryptedContent); 
   $user_store_pic_name = $lastUserId.'_'.time().'.' .$encryptedContent->getClientOriginalExtension();
   $filePath = 'store/'.$user_store_pic_name;
   $s3->put($filePath, file_get_contents($encryptedContent));
   $userStorePicName = $filePath;
   $userfile->user_store_pic = $userStorePicName;
   $userfile->save();
}

I am trying to encrypt the file as per https://stefanzweifel.io/posts/how-to-encrypt-file-uploads-with-laravel/

but I got an error when I submit the form:

"ymfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call to a member function getClientOriginalExtension() on string"

I try to convert into an array using explode but it shows the same error for an array:

"Call to a member function getClientOriginalExtension() on array"

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Sagar Parikh
  • 288
  • 5
  • 20

1 Answers1

0

You have to use $user_store_pic->getClientOriginalExtension(); in place of $encryptedContent->getClientOriginalExtension()

It may help you.

Rahul Rai
  • 101
  • 6
  • I already try that, its shows ErrorException (E_WARNING), "file_get_contents(eyJpdiI6Im5qVHI0TVBTNEtWSHorbXY0RVB4eHc9PSIsInZhbHVlIjoiZTk1ZmpSUjVENmlBMlJ5TWsxa3hFQnNPdnpzTmdLeVU5RWQySGNZdkVLRGs2bzRId3dZT2ZiVDdGTFBjTlZNcm ▶" – Sagar Parikh Jun 29 '19 at 05:56
  • Try to use this: ``` $file = $request->file('attachment'); // Get File Content $fileContent = $file->get(); // Encrypt the Content $encryptedContent = encrypt($fileContent); // Store the encrypted Content $s3->put($filePath, $encryptedContent); ``` – Rahul Rai Jun 29 '19 at 06:14
  • still received same error: "Call to a member function getClientOriginalExtension() on string" – Sagar Parikh Jun 29 '19 at 06:23
  • Have you got error "Call to a member function getClientOriginalExtension() on string" after using this "$user_store_pic->getClientOriginalExtension()" ? – Rahul Rai Jun 29 '19 at 06:24
  • 1
    @SagarParikhSGR You are doing a poor job debugging your code. How about figuring out what the variables are before using them. This way you are not assuming what the variables content is. Laravel includes a nice helper function call `dd()` – Pablo Jun 29 '19 at 06:25
  • @RahulRai yes its shows same error after use this "$user_store_pic->getClientOriginalExtension()" – Sagar Parikh Jun 29 '19 at 07:43