在Laravel中显示解密的图像

时间:2019-07-01 10:55:22

标签: php laravel encryption

我是Laravel的新手,可以在上传时加密图像,但是现在我只能显示图像。 我关注的博客是https://stefanzweifel.io/posts/how-to-encrypt-file-uploads-with-laravel/

我的控制器中有两种方法,因此情况是注册方法将对文件进行加密,而视图方法将将解密数据发送至视图,并与路径匹配并显示图像。

如果我使用错误的逻辑,请纠正我。

这是我在控制器中用于图像加密的注册方法:

public function main_register_store(Request $request)
{
    $user_store_pic = $request->file('user_store_pic');
    $fileContent = $user_store_pic->get();
    $encryptedContent = encrypt($fileContent);
    $decryptedContent = decrypt($encryptedContent);

    // Build unique Filename and Path
    $user_store_pic_name = $lastUserId.'_'.time().'.'.$user_store_pic->getClientOriginalExtension();
    $filePath = 'store/'.$user_store_pic_name;

    // Store to Disk
    $s3 = \Storage::disk('uploads')->put($filePath, $encryptedContent);

    // Update Model
    $userfile = DNEUser::find($lastUserId);
    $userfile->user_store_pic = $filePath;
    $userfile->save();

    msg($dne, 'User Registered Successfully', 'Oops...something went wrong');
    //I am trying to send value to other method which is loading my view 
    $exportdrypt = $this->main_network($decryptedContent);

    return redirect()->back();
}

这是另一种加载视图的方法:

  public function main_network(Request $request, $decryptedContent="") 
  {
  session()->put('forms.user', $request->get('user_industry'));
  $user_industry = $request->has('user_industry') ? $request->get('user_industry') : null;
  $user_buisness = $request->has('user_business_name') ? $request->get('user_business_name') : null;
  $user_profession = $request->has('user_profession') ? $request->get('user_profession') : null;
  $users = DNEUser::where('role_id',0)->where('user_status','accepted');
  $users = $users->get();
  return $this->getView('dne.network',compact('page_title','page_description', 'users','user_industry','user_profession','user_buisness','decryptedContent'));
  }

这是来自view:network.blade.php的代码

      <img src="{{URL::asset('uploads/')."/".$user->user_store_pic}}" alt="Placeholder image">
      <?php // file_put_contents("{{URL::asset('uploads/')."/".$user->user_store_pic}}",$decryptedContent); ?>

错误

  

“遇到一个非数字值(视图:C:\ Users \ Admin \ Documents \ GitHub \ Invoice \ resources \ views \ dne \ network.blade.php)”

0 个答案:

没有答案