【问题标题】:Laravel 5.2 - Intervation image, save base64 input imagesLaravel 5.2 - 干预图像,保存base64输入图像
【发布时间】: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]);

返回这个:

【问题讨论】:

    标签: php laravel base64


    【解决方案1】:

    使用

    foreach($image_array as $key => $image) {
        $file = base64_decode($image);
    

    错误发生在您的for 循环中,您使用的是数值,但您的$image_array 具有非数字索引。第一个索引不是0,而是dsdas.PNG

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2016-12-19
      • 2017-01-25
      • 2020-01-19
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2017-01-06
      相关资源
      最近更新 更多