Summer Sale! All accounts are 50% off this week.

david001's avatar

summernote update throws error:Undefined offset: 1

I have used summer note in my project.https://summernote.org/

I can create the post with summernote. I can attach the images to my content as well. However, when I click the edit button and add a few photos in textarea and click the update button, it gives me an error

Undefined offset: 1

update:


$service = Service::find($id);

        $detail = $request->get('description');
        libxml_use_internal_errors(true);

        $dom = new \DomDocument();

        $dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);  
          

        $images = $dom->getElementsByTagName('img');

        foreach($images as $k => $img){

            $data = $img->getAttribute('src');

            list($type, $data) = explode(';', $data);

            list(, $data)      = explode(',', $data);

            $data = base64_decode($data);

            $image_name= "/upload/" . time().$k.'.png';

            $path = public_path() . $image_name;

            file_put_contents($path, $data);

            $img->removeAttribute('src');

            $img->setAttribute('src', $image_name);

        }

        $detail = $dom->saveHTML();
        $service->description = $dom->saveHTML();
        $service->name = $request->get('name');
        $service->save();

Any help would be hightly appreciate

0 likes
1 reply
Moinul's avatar

if your are try to update you just need add something in your code :

if (strpos($data, 'data') !== false) { list($type, $data) = array_pad(explode(';', $data),2,null); list(, $data) = array_pad(explode(',', $data),2,null); $dataConvert = base64_decode($data); ........... ................ }

just check whether its contain data string or not that will solve your problem ,Because when you updating in summer note its can not the contain the full image object $data = $img->getAttribute('src'); just return a string

Please or to participate in this conversation.