如何在Laravel7中更新图像Summernote?

如何在Laravel7中更新图像Summernote?,laravel,file-upload,laravel-7,summernote,laravel-controller,Laravel,File Upload,Laravel 7,Summernote,Laravel Controller,我在共享主机上更新更多图像时遇到问题,但在我的本地计算机上一切正常 我从共享主机收到此错误。 file_put_contents(/public/storage/article_image/post_162069532710.png): failed to open stream: No such file or directory 这是我的更新功能 $detail=$request->messageInput; $dom = new \domdocume

我在共享主机上更新更多图像时遇到问题,但在我的本地计算机上一切正常

我从共享主机收到此错误。

file_put_contents(/public/storage/article_image/post_162069532710.png): failed to open stream: No such file or directory
这是我的更新功能

        $detail=$request->messageInput;
        $dom = new \domdocument('1.0', 'UTF-8');
        @$dom->loadHtml('<?xml encoding="UTF-8">'.$detail);
        libxml_use_internal_errors(true);
      
        $images = $dom->getelementsbytagname('img');
        $bs64='base64';//variable to check the image is base64 or not
       
        foreach($images as $k => $img){
            $data = $img->getattribute('src');
            if (strpos($data,$bs64) == true)//if the Image is base 64
            {
                $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
                $image_name = "/storage/article_image/". 'post_' . time() . $k . '.png';
                $path = public_path() . $image_name;
                file_put_contents($path, $data);
                $img->removeAttribute('src');
                $img->setAttribute('src', $image_name);
                }
                else
                {
                    $image_name="".$data;
                    $img->setAttribute('src', $image_name);
                }
              };
              $detail = $dom->savehtml();

        $article=Article::find($id);
        $article->articlecategory_id=$request->articlecategory_id;
        $article->title=$request->title;
        $article->keyword=$request->keyword;
        $article->shortdetail=$request->shortdetail;
        $article->fulldetail = $detail;
        $article->updated_by=Auth::id();
        $article->status_id=$request->status_id;

        $article->save();
$detail=$request->messageInput;
$dom=new\domdocument('1.0','UTF-8');
@$dom->loadHtml(“”.$detail);
libxml\u使用\u内部错误(true);
$images=$dom->getelementsbytagname('img');
$bs64='base64'//用于检查映像是否为base64的变量
foreach($k=>$img的图像){
$data=$img->getattribute('src');
if(strpos($data,$bs64)==true)//如果映像是base 64
{
$data=base64_解码(preg#u替换(“#^data:image/\w+;base64,#i',”$data));
$image_name=“/storage/article_image/”'post_'.time().$k..png';
$path=public\u path().$image\u name;
文件内容($path,$data);
$img->removeAttribute('src');
$img->setAttribute('src',$image\u name);
}
其他的
{
$image_name=”“.$data;
$img->setAttribute('src',$image\u name);
}
};
$detail=$dom->savehtml();
$article=article::find($id);
$article->articlecategory\u id=$request->articlecategory\u id;
$article->title=$request->title;
$article->keyword=$request->keyword;
$article->shortdetail=$request->shortdetail;
$article->fulldetail=$detail;
$article->updated_by=Auth::id();
$article->status\u id=$request->status\u id;
$article->save();
表单上传

                                        <div class="mx-auto col-md-8">
                                            {{csrf_field()}}
                                            <textarea name="messageInput" class="summernote" minlength="300" maxlength="5100" required>{{$articles->fulldetail}}</textarea>
                                            <span class="text-danger">{{ $errors->first('fulldetail') }}</span>
                                        </div>

{{csrf_field()}}
{{$articles->fulldetail}
{{$errors->first('fulldetail')}

我已经困了大约两天了。请提供帮助:[

如果您尝试将文件放入不存在的目录中,文件内容将失败。在本地,您有目录
/public/storage/article\u image/
,因此不会出现此错误,但在共享主机中不会。您应该在将数据写入文件之前检查目录是否存在

   $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data)); 
   $dir = public_path() . "/storage/article_image";
    if( !is_dir( $dir ) ) {
        mkdir( $dir, 0777, true ); 
    }
    $path = $dir. '/post_' . time() . $k . '.png';
    file_put_contents($path, $data);