Laravel:加密上传的文件/图像
我是新来的,请尝试加密上传的文件。这是我的控制器:Laravel:加密上传的文件/图像,laravel,encryption,laravel-encryption,Laravel,Encryption,Laravel Encryption,我是新来的,请尝试加密上传的文件。这是我的控制器: if ($file != null && !empty($file)) { $userfile = DNEUser::find($lastUserId); $user_store_pic = $request->file('user_store_pic'); $fileContent = $user_store_pic->get(); $encryptedContent = encrypt(
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();
}
我正在尝试按照加密文件
但我在提交表单时出错:
“ymfony\Component\Debug\Exception\FatalThroTableError
(E_错误)调用上的成员函数getClientOriginalExtension()
“字符串”
我尝试使用explode转换为数组,但它显示了与数组相同的错误:
“对数组上的成员函数getClientOriginalExtension()的调用”
您必须使用
$user\u store\u pic->getClientOriginalExtension();
代替$encryptedContent->getClientOriginalExtension()
它可能会对您有所帮助。更换这个
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().'.' .$user_store_pic->getClientOriginalExtension();
$filePath = 'store/'.$user_store_pic_name;
$s3->put($filePath, $encryptedContent);
$userStorePicName = $filePath;
$userfile->user_store_pic = $userStorePicName;
$userfile->save();
}
我已经尝试过了,它显示了ErrorException(E_警告),“文件获取内容(EYJPDii6im5qvhi0tVbtNetworkshorbxy0Rb4ehc9PsisinzHbhLijoiztk1zmpsujvenmlbmlj5twsxa3hfqnnpdnpztmdLevu5rwqysgnzdkvlsgs2bzridzt2zivddgtfBjlzncm▶"尝试使用以下方法:```$file=$request->file('attachment');//获取文件内容$fileContent=$file->Get();//加密内容$encryptedContent=Encrypt($fileContent);//存储加密内容$s3->put($filePath,$encryptedContent);``仍然收到相同的错误:“调用字符串上的成员函数getClientOriginalExtension()使用此“$user\u store\u pic->getClientOriginalExtension()”后,是否出现错误“调用字符串上的成员函数getClientOriginalExtension()”?@SagarParikhSGR您在调试代码时做得很差。在使用变量之前先弄清楚变量是什么。这样您就不会假设变量的内容是什么。Laravel包含了一个很好的帮助函数调用
dd()
its shows ErrorException(E\u警告),“file\u get\u contents”(EYJPDII6IM5QVHI0TvBTnetwshorbxy0RVB4EHC9PSISINZHBHVLIJOIZTK1ZMPSUJVENLBMLJ5TWSXA3HFQNNPDNPZTMDLEVU5RWQYSGNZDKVLGS2BZRID3ZT2 ZIDZT2 ZIDGDGTFBJTLZNCM删除文件以替换此行$s3->->put($filePath,$encryptedContent);例外情况:不允许序列化“Lightlight\Http\UploadedFile”