layedit图片上传接口案列

html部分

<divclass="layui-form-item">
	<labelfor="tname"class="layui-form-label">
		<spanclass="x-red">*</span>内&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp容
	</label>
	<divclass="layui-input-block">
		<textareaid="content"style="display:none;"></textarea>
	</div>
</div>

js部分

layui.use(['form','layer','layedit'],function(){
	$=layui.jquery;
	var form=layui.form
	,layer=layui.layer
	,layedit=layui.layedit;
	
	layedit.set({
		uploadImage:{
		url:"upload"//接口url
		,type:''//默认post
	}
});
//注意:layedit.set一定要放在build前面,否则配置全局接口将无效。
layedit.build('content');//建立编辑器

php

//上传
publicfunctionupload()
{
	$file=request()->file('file');
	$info=$file->move(ROOT_PATH.'public'.DS.'uploads');
	$src=ROOT_PATH.'public'.DS.'uploads'.DS.$info->getSaveName();
	$title=$info->getFilename();
	if($info){
		$data=[
			'data'=>['src'=>$src,'title'=>$title],
			'code'=>1,
			'msg'=>'上传成功',
		];
		return$data;
	}else{
		echo$file->getError();
	}
}
posted @ 2019-04-23 19:54  琴似蓝调  阅读(...)  评论(...编辑  收藏