在共享托管中使用summernote时出现Laravel错误

时间:2019-06-13 03:45:56

标签: php laravel summernote

我写的代码是这样的:

public function saveNews(Request $request)
{
    $this->validate($request,[
        'title'    =>'required|unique:articles,title', 
        'content'      =>'required',
        'category' =>'required',
        'images.*'  =>'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);

    $images = $request->images;
    $artikel = new article;
    //content
    $content=$request->content;
    $dom = new \domdocument();
    $dom->loadHtml($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    $images = $dom->getelementsbytagname('img');

    //loop over img elements, decode their base64 src and save them to public folder,
    //and then replace base64 src with stored image URL.
    foreach($images as $k => $img){
        $data = $img->getattribute('src');

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

        $data = base64_decode($data);
        $image_name= time().$k.'.png';
        $path = public_path() .'/img'. $image_name;

        file_put_contents($path, $data);

        $img->removeattribute('src');
        $img->setattribute('src', $image_name);
    }

    $data = array();
    $files = $request->file('gambar');
    foreach($files as $file)
    {   
        $extension = $file->getClientOriginalExtension();

        //create random name with ext
        $filename = md5(time()).'.'.$extension;
        //save image to public
        $destinationPath = public_path().DIRECTORY_SEPARATOR.'img';
        $file->move($destinationPath, $filename);
        $data[] = $filename;
    }

    $content = $dom->savehtml();
    $artikel->content = $content;
    $artikel->title = $request->title;
    $artikel->category_id = $request->category;
    $artikel->slug = Str::slug($request->get('title'));
    $artikel->images =implode($data);
    $artikel->save();

    return redirect('/masterBerita')->with('message','News Has Been Posted..');
}

我正在使用Laravel 5.5和Summer note,从文档中我认为这是正确的,我尝试在localhost上运行并通过,但是上传到服务器后,出现此错误

  

使用未定义的常量LIBXML_HTML_NOIMPLIED-假定为'LIBXML_HTML_NOIMPLIED

0 个答案:

没有答案