一:添加页面:
add.html:
<include file="Index/header" />
<body>
<div id="wrapper">
<include file="Index/nav"/>
<script src="/Public/js/kindeditor/kindeditor-all.js"></script>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> <a href="/index.php/admin/content">文章管理</a>
</li>
<li class="active">
<i class="fa fa-edit"></i> 文章添加
</li>
</ol>
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-6">
<form class="form-horizontal" id="singcms-form">
<div class="form-group">
<label for="inputname" class="col-sm-2 control-label">标题:</label>
<div class="col-sm-9">
<input type="text" name="title" class="form-control" id="inputname" placeholder="请填写标题">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-2 control-label">短标题:</label>
<div class="col-sm-9">
<input type="text" name="small_title" class="form-control" id="inputname" placeholder="请填写短标题">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">描述:</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="description" id="inputPassword3" placeholder="描述">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">关键字:</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="keywords" id="inputPassword3" placeholder="请填写关键词">
</div>
</div>
<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"> <!-- 允许N张上传-->
<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>
<div class="form-group">
<label for="inputname" class="col-sm-2 control-label">标题颜色:</label>
<div class="col-sm-5">
<select class="form-control" name="title_font_color">
<option value="">==请选择颜色==</option>
<foreach name="titleFontColor" item="color">
<option value="{$key}">{$color}</option>
</foreach>
</select>
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-2 control-label">所属栏目:</label>
<div class="col-sm-5">
<select class="form-control" name="catid">
<foreach name="webSiteMenu" item="sitenav">
<option value="{$sitenav.menu_id}">{$sitenav.name}</option>
</foreach>
</select>
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-2 control-label">来源:</label>
<div class="col-sm-5">
<select class="form-control" name="copyfrom">
<foreach name="copyfrom" item="cfrom">
<option value="{$key}">{$cfrom}</option>
</foreach>
</select>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">内容:</label>
<div class="col-sm-5">
<textarea class="input js-editor" id="editor_singcms" name="content" rows="20" ></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" id="singcms-button-submit">提交</button>
</div>
</div>
</form>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<script>
var SCOPE = {
'save_url' : '/index.php/admin/content/add',
'jump_url' : '/index.php/admin/content',
'ajax_upload_image_url' : '/index.php/admin/image/ajaxuploadimage',
'ajax_upload_swf' : '/Public/js/party/uploadify.swf',
};
</script>
<!-- /#wrapper -->
<script>
/**
* 图片上传功能
*/
$(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) { //①上传文件,② ,③相应
console.log("response:上传成功则返回true ="+response);
if(response) {
var obj = JSON.parse(data); //由JSON字符串转换为JSON对象
if(obj.message=="上传失败"){
alert(obj.message);
}
console.log(obj);
//file是swf插件的属性:上传文件对象
console.log("数据测试02 "+data);
$('#' + file.id).find('.data').html(' 上传完毕'); //find遍历一个对象
//显示图片
$("#upload_org_code_img").attr("src",obj.data);//图片名称
$("#file_upload_image").attr('value',obj.data);//显示图片
$("#upload_org_code_img").show();
console.log("datetest++"+$("#upload_org_code_img").attr('src'));
}else{
alert('上传失败');
}
},
});
});
</script>
<script>
// 6.2
/* KindEditor.ready(function(K) {
window.editor = K.create('#editor_singcms',{
uploadJson : '/index.php/admin/image/kindupload',
afterBlur : function(){this.sync();},
});
}); */
</script>
<include file="Index/footer" />
二:控制层:
ImageControll.class.php
<?php
/**
* 图片相关
*/
namespace Admin\Controller;
use Think\Controller;
use Think\Upload;
/**
* 文章内容管理
*/
class ImageController extends CommonController {
public $_uploadObj;
public function __construct() {
}
public function ajaxuploadimage() {
//实例UploadImage模板
//$res = $upload->imageUpload();
//print_r($res);
$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();
if($res === false) {
return showKind(1,'上传失败');
}
return showKind(0,$res);
}
}
三:模板层
UploadImageModel.class.php
<?php
namespace Common\Model;
use Think\Model;
/**
* 上传图片类
* @author singwa
*/
class UploadImageModel extends Model {
public $_uploadObj = '';
public $_uploadImageData = '';
const UPLOAD = 'upload';
public function __construct() { /* 结合thinkPHP提供的类,公共函数*/
$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() {
$this->_uploadObj = new \Think\Upload(); /* 实例化类*/
$this->_uploadObj->rootPath = './'.self::UPLOAD.'/';
$this->_uploadObj->subName = date(Y) . '/' . date(m) .'/' . date(d);
$res = $this->_uploadObj->upload();
return '/' .self::UPLOAD . '/' . $res['file']['savepath'] . $res['file']['savename'];
}else{
return false;
}
}
}
请各位大神帮忙解答一下 谢谢;?