tp5异步上传生成缩略图

浏览:5720 发布日期:2017/04/28 分类:功能实现 关键字: tp5 异步上传 略缩
记得引入上传js文件tpUpload.js

1.html<input type="file" name="pic1" id="imgPicker" />   
<input type="hidden"  id="pic1" value="NULL"/>
2.js$("#imgPicker").tpUpload({
        url: '{:\\think\\Url::build("service/upload1")}',
        data: {a: 'a'},
        size: '10Mb',
        drag: '#drag',
        start: function () {
            layer_msg = layer.msg('正在上传中…', {time: 100000000});
        },
        progress: function (loaded, total, file) {
            $('.layui-layer-msg .layui-layer-content').html('已上传' + (loaded / total * 100).toFixed(2) + '%');
        },
        success: function (ret) {            
            $("#pic1").val(ret.data);
            //layer.alert(ret);
        },
        error: function (ret) {
            layer.alert(ret);
        },
        end: function () {
            layer.close(layer_msg);
        }
    });
3.控制器public function upload1()
    {
        $pic1 =  '/tmp/uploads/1/' . time().'.jpg'; //数据库存的路径
        $pic =  ROOT_PATH.'public'.$pic1; //生成略缩图需要的绝对路径
        $file1 = $this->request->file('pic1');      
        if($file1)
        {
            Image::open($file1)->thumb(150, 150)->save($pic);  
        }else
        {
            $file1->getError();
        }      
        return ajax_return($pic1);
    }
评论( 相关
后面还有条评论,点击查看>>