0

我使用签名板,当我更新记录时它显示“未定义的偏移量:1”。

场景:

  1. 用户创建了他们必须在其上签名的记录。
  2. 用户发送记录以请求批准。
  3. 授权人使用签名板在记录上签名。
  4. 记录发送到下一个部门以编辑记录上的某些字段。<<<在这种情况下发生的错误

这是我的编辑表格

                    <div class="mb-3 row">
                            <label  class="col-sm-2 form-label align-self-center mb-lg-0 text-end">Signature:</label>
                            <br/>
                            <div class="col-sm-10">
                                 <div id="signaturePad" ></div>
                                 <br/>
                                 <button id="clear" class="btn btn-danger">Delete</button>
                                 <textarea id="signature64" name ="signed" style="display: none"> 
                                 </textarea>
                                 <span class="text-danger">{{ $errors->first('signed') }}</span>
                            </div>
                    </div>




    <!-- Signature -->

    <script type="text/javascript" src="http://keith-wood.name/js/jquery.signature.js"></script>
    <link rel="stylesheet" type="text/css" href="http://keith-wood.name/css/jquery.signature.css">
    <script type="text/javascript">
        var signaturePad = $('#signaturePad').signature({syncField: '#signature64', syncFormat: 'PNG'});
        $('#clear').click(function(e) {
        e.preventDefault();
        signaturePad.signature('clear');
        $("#signature64").val('');
        });
    </script>

    <!-- Signature -->

我的控制器

       public function update(Request $request,$id){
        $request->validate([
            /*'contactgroup_id' => 'nullable', 'string', 'max:25',
            'code' => 'nullable|string', 'max:25',
            'name' => 'sometimes|string', 'max:255',
        ]);


        $folderPath = storage_path('app/private/esigns/');

        $image_parts = explode(";base64,", $request->signed);

        $image_type_aux = explode("image/", $image_parts[0]);

        $image_type = $image_type_aux[1];

        $image_base64 = base64_decode($image_parts[1]);

        $signature = uniqid() . '.'.$image_type;

        $file = $folderPath . $signature;

        file_put_contents($file, $image_base64);


        $tickets =Ticket::find($id);
        $tickets->signature = $signature;
        $tickets->save();
        }

        }

更新签名记录时出现此错误。

ErrorException
Undefined offset: 1

 $folderPath = storage_path('app/private/esigns/');

 

        $image_parts = explode(";base64,", $request->signed);

 

        $image_type_aux = explode("image/", $image_parts[0]);

 

        $image_type = $image_type_aux[1];

 

        **$image_base64 = base64_decode($image_parts[1]);** The error is highlighted on this line

 

        $signature = uniqid() . '.'.$image_type;

 

        $file = $folderPath . $signature;

 

        file_put_contents($file, $image_base64);

有什么解决方案可以解决这个问题?

请给我一些建议。谢谢你。

4

0 回答 0