【发布时间】:2019-02-06 08:10:34
【问题描述】:
我得到一个格式为 String base64 的图像,我想将该字符串解码为图像并将其保存到 laravel 的公共文件夹中。
这是我的控制器:
//decode string base64 image to image
$image = base64_decode($request->input('ttd'));
//create image name
$photo_name = time().'.png';
$destinationPath = public_path('/uploads');
//save image to folder
$image->move($destinationPath, $photo_name);
$img_url = asset('/uploads'.$photo_name);
$data = new Transaction();
$data->transaction_id = $request->input('fa_transaction_id');
$data->user_id = $request->input('userid');
$data->photo_name = $photo_name;
$data->photo_url = $img_url;
$data->save();
当我尝试 echo $image 时,我得到了解码值,对于 $photo_name 我也得到了值,但是当函数运行时我得到了这个错误
Call to a member function move() on string
如何解决这个错误?
【问题讨论】:
-
这里没有任何类型的“文件”对象可以有
move方法,你有一个字符串,不多也不少。所以你需要自己把那个字符串写到一个文件中。
标签: php laravel laravel-4 php-7