首页 > 解决方案 > 如何修复此错误 Undefined offset: 1 in line 178

问题描述

数据库:

$data = $_POST["input1"];       
$data = explode(",", $data)[1]; // line 178
$decoded_image = base64_decode($data);
$temp_name = 'img/'.md5(time().rand().time()).".png";
file_put_contents($temp_name, $decoded_image);
// Store this $file to table.
$file = basename($temp_name);

如何修复此错误

标签: php

解决方案


$data 变量的 1 个索引,因此具有变量的右索引,就像这样

$data = explode(",", $data[1]);


推荐阅读