<?php /**图片相关 */namespace Admin\Controller;use Think\Controller;use Think\Upload;/*** 文章内容管理 */class ImageController extends CommonController{ private $_uploadobj; public function __construct(){ } //异步上传方法 public function ajaxuploadimage(){ $upload = D("UploadImage"); $res = $upload->imageUpload(); if($res===false){ return show(0,'上传失败', ' '); }else{ return show(1,'上传成功',$res); } } //文本编辑器的接受 public function kindupload(){ $upload = D("UploadImage"); $res = $upload->upload(); print_r($res); exit; if($res===false){ return showkind(1,'上传失败'); } return showkind(0,$res); }}?>上面的代码是ImageController.class.php<?phpnamespace Common\Model;use Think\Model;/** * 上传图片类 * @author singwa */class UploadImageModel extends Model { private $_uploadObj = ' '; private $_uploadImageData = ' '; const UPLOAD = 'upload'; public function __construct() { $this->_uploadObj = new \Think\Upload(); $this->_uploadObj->rootPath = './'.self::UPLOAD.'/'; $this->_uploadObj->subName = date(Y) . '/' . date(m) .'/' . date(d); } public function upload() { $res = $this->_uploadObj->upload(); if($res) { return '/' .self::UPLOAD . '/' . $res['imgFile']['savepath'] . $res['imgFile']['savename']; }else{ return false; } } public function imageUpload() { $res = $this->_uploadObj->upload(); // print_r($res);exit; if($res) { return '/' .self::UPLOAD . '/' . $res['file']['savepath'] . $res['file']['savename']; }else{ return false; } }}上面加粗的这段代码是UploadImageModel.class.php下面的代码是Image.js/** * 图片上传功能 */$(function() { $('#file_upload').uploadify({ 'swf' : SCOPE.ajax_upload_swf, 'uploader' : SCOPE.ajax_upload_image_url, 'buttonText': '上传图片', 'fileTypeDesc': 'Image Files', 'fileObjName' : 'file', //允许上传的文件后缀 'fileTypeExts': '*.gif; *.jpg; *.png', 'onUploadSuccess' : function(file,data,response) { // response true ,false if(response) { var obj = JSON.parse(data); //由JSON字符串转换为JSON对象 console.log(data); $('#' + file.id).find('.data').html(' 上传完毕'); $("#upload_org_code_img").attr("src",obj.data); $("#file_upload_image").attr('value',obj.data); $("#upload_org_code_img").show(); }else{ alert('上传失败'); } }, });});<div class="form-group"> <label for="inputname" class="col-sm-2 control-label">缩图:</label> <div class="col-sm-5"> <input id="file_upload" type="file" multiple="true" > <img style="display: none" id="upload_org_code_img" src="" width="150" height="150"> <input id="file_upload_image" name="thumb" type="hidden" multiple="true" value=""> </div> </div><script> var SCOPE = { 'save_url' : "{:U('/admin.php?c=content&a=add')}", 'jump_url' : "{:U('/admin.php?c=content')}", 'ajax_upload_image_url' : "{:U('/admin.php?c=image&a=ajaxuploadimage')}", 'ajax_upload_swf' : "{:U('/Public/js/party/uploadify.swf')}", };</script>
添加回答
举报
0/150
提交
取消