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);
} 