Home>Article>Backend Development> Code example for uploading images using tp3.2 and mbUploadify.js

Code example for uploading images using tp3.2 and mbUploadify.js

little bottle
little bottle forward
2019-04-22 15:35:35 1596browse

This article mainly talks about using tp3.2 and mbUploadify.js to upload pictures. It has certain reference value. I would like to share it with you. Friends who are interested can learn about it!

HTML:

CSS:

JS:

 

PHP:

public function mbUploadImg(){ $upload = new Upload(); // 实例化上传类 $upload->maxSize = 5242880 ; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Public/'; // 上传文件 $info = $upload->uploadOne($_FILES['files']); if($info) { // 上传成功 $data['name'] = $info['name']; $data['ext'] = $info['ext']; $data['type'] = $info['type']; $data['savename'] = $info['savename']; $data['savepath'] = "/Public/".$info['savepath'].$info['savename']; $imgId = M('upload_img')->add($data); if($imgId){ $resData['code'] = 200; $resData['msg'] = '成功'; $resData['id'] = $imgId; $resData['name'] = $data['name']; $resData['savepath'] = $data['savepath']; echo json_encode($resData); return; } } // 上传错误提示错误信息 return $this->ajaxReturn(['code'=>400,'msg'=>$upload->getError()]); }

Related tutorials:

PHP video tutorial

HTML video tutorial

CSS video tutorial

##js Video tutorial

The above is the detailed content of Code example for uploading images using tp3.2 and mbUploadify.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete