ThinkPHP文件上传
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <?php class UploadFileAction extends Action{ public function index() { $Photo = M('Photo'); $data = $Photo->order('create_time desc')->find(); $this->assign('data', $data); $this->display(); }
public function upload() { if (!empty($_FILES)) { $this->_upload(); } }
protected function _upload() { import('@.ORG.UploadFile'); $upload = new UploadFile(); $upload->maxSize = 3292200; $upload->allowExts = explode(',', 'jpg,gif,png,jpeg'); $upload->savePath = './Uploads/'; $upload->thumb = true; $upload->imageClassPath = '@.ORG.Image'; $upload->thumbPrefix = 'm_,s_'; $upload->thumbMaxWidth = '400,100'; $upload->thumbMaxHeight = '400,100'; $upload->saveRule = 'uniqid'; $upload->thumbRemoveOrigin = true; if (!$upload->upload()) { $this->error($upload->getErrorMsg()); } else { $uploadList = $upload->getUploadFileInfo(); import('@.ORG.Image'); Image::water($uploadList[0]['savepath'] . 'm_' . $uploadList[0]['savename'], APP_PATH.'Tpl/Public/Images/logo.png'); $_POST['image'] = $uploadList[0]['savename']; } $model = M('Photo'); $data['image'] = $_POST['image']; $data['create_time'] = NOW_TIME; $list = $model->add($data); if ($list !== false) { $this->success('上传图片成功!'); } else { $this->error('上传图片失败!'); } } } ?>
|
更多精彩内容,请关注公众号
感谢赞赏.
WeChat Pay
Welcome to my other publishing channels