标签 layui 下的文章

html+js

<textarea id="demo" style="display: none;"></textarea>
<script>
    layui.use('layedit', function(){
    var layedit = layui.layedit;
    uploadImage: {
        //上传操作 后台Article控制器的layeditUpload方法
        url: '{:U("Admin/Article/layeditUpload")}' //接口url
        ,type: '' //默认post
    }
    layedit.build('demo'); //建立编辑器
    });
</script>

php接收上传代码

public function layeditUpload(){
    $file = request()->file('file');
    // 移动到框架应用根目录/public/uploads/ 目录下
    $info = $file->move(ROOT_PATH . 'public' . DS . 'layeditUpload');
    $reubfo = array();  //定义一个返回的数组
    if($info){
        $reubfo['code']= 0;
        $reubfo['msg']= '上传成功';
        $reubfo['data']['src']= "/layeditUpload/".$info->getSaveName(); 
    }else{
        // 上传失败获取错误信息
        $reubfo['code']= -1;
        $reubfo['err'] = $file->getError();
    }
    return json($reubfo);
}

1.HTML部分
<div class="layui-upload" style="margin-left:110px;">

<button type="button" class="layui-btn" id="test1">更新头像</button>
<div class="layui-upload-list">
    <img class="layui-upload-img" id="demo1" src="{$data.icon??''}">
    <p id="demoText"></p>
</div>

</div>
注: img的src的值是做的回选,根据需要选择



- 阅读全部 -