【发布时间】:2016-12-07 16:10:26
【问题描述】:
我正在将图像 base64 传递给我的控制器输入,我正在使用交互图像来调整大小、使用画布、保存图像。但我在解码图像 base64 时遇到了一些问题:
PostController.php 第 163 行中的 ErrorException:需要 base64_decode() 参数1为字符串,给定数组
public function creaPost(Request $request){
$image_array = $request->input('image'); // input image base64
$contare = count($image_array);
for($i = 0; $i < $contare; $i++) {
$file = base64_decode($image_array[$i]);
if (!empty($file)) {
$background = Image::canvas(550, 550);
$image2 = Image::make($file)->encode('jpg', 100)- >resize(550, 550, function ($c) {
$c->aspectRatio();
$c->upsize();
});
... my code...etc..
$store_path->save();
}
}
}
$file = base64_decode($image_array[$i]); 行返回错误,我不知道如何才能很好地解码我的数组图像。
也许可以帮助 如果我这样做:
$image_array = $request->input('image');
return dd($image_array[1]);
【问题讨论】: