Reputation: 1353
i'm passing to my controller input with images base64, i'm using intervation image to resize, use canvas, save images. but i have some problem with decode image base64:
ErrorException in PostController.php line 163: base64_decode() expects parameter 1 to be string, array given
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();
}
}
}
the line $file = base64_decode($image_array[$i]);
return the error, i don't know how can i decode well my array images.
MAYBE CAN HELP if i do:
$image_array = $request->input('image');
return dd($image_array[1]);
Upvotes: 1
Views: 3208
Reputation: 1282
Use
foreach($image_array as $key => $image) {
$file = base64_decode($image);
Error occurs cause in your for
loop you are using numeric values, but your $image_array
has non-numeric indexes. First index wasn't 0
but dsdas.PNG
Upvotes: 2