<script type= "Text/javascript" src= "/statics/js/kindeditor/kindeditor-min.js" ></script>
<script type= "Text/javascript" src= "/statics/js/kindeditor/zh_cn.js" ></script>
<script type= "Text/javascript" src= "/statics/js/uploadify/jquery.uploadify.min.js" ></script>
<script type= "Text/javascript" src= "/statics/js/kindeditor/default/default.css" ></script>
<script charset= "Utf-8" src= "/statics/js/kindeditor/plugins/code/prettify.js" ></script>
<link rel= "stylesheet" href= "/statics/js/kindeditor/plugins/code/prettify.css"/>
Html:
<div class= "Form-group" >
<label class= "Col-md-2 Control-label" > article content:</label>
<div class= "Col-md-9" >
(Page breaks are:
<span style= "color:red" > #p # Page-title #e#) </span>
<span>
<label>
<input id= "autolitpic" type= "checkbox" >
Extract the first image as a thumbnail image
</label>
(
<a class= "qximg" href= "javascript:void ();" >[Cancel thumbnail image]</a>
)
</span>
<span style= "color:red" >*</span>
<div class= "OnShow" id= "dr_content_tips" > Required fields, unlimited input, no word limit .</div>
<label class= "textarea" ><textarea name= "content" id= "content" class= "content" onblur= "content_validate ()" >{$info. content|default= "}</textarea>
<input type= "hidden" name= "parse" value= "0" > <script
Type= "Text/javascript" >
var editor_content1;
Kindeditor.ready (function (K) {
Editor_content1 = k.create (' textarea[name= "content"] ', {
Allowfilemanager:false,
Themespath:k.basepath,
Width: ' 900px ',
Height: ' 700px ',
Resizetype:1,
Pastetype:2,
Urltype: ' Absolute ',
Csspath: '/statics/js/kindeditor/plugins/code/prettify.css ',
Uploadjson: ' {: U (' ke_upimg ')} ',
Aftercreate:function () {
This.sync ();
},
Afterblur:function () {
This.sync ();
}
});
Prettyprint ();
});
</script>
</label>
</div>
</div>
Background code
Keditor Editor Upload image processing
Public Function ke_upimg () {
/* Return standard data */
$return = Array (' ERROR ' = 0, ' info ' = ' upload succeeded ', ' data ' = ');
$img = $this->upload ();
/* Record attachment information */
if ($img) {
$return [' url '] = $img [' FullPath '];
unset ($return [' info '], $return [' data '];
} else {
$return [' ERROR '] = 1;
$return [' message '] = Session (' Upload_error ');
}
/* Return JSON data */
Exit (Json_encode ($return));
}
/* Upload picture */
Public function upload () {
Session (' Upload_error ', null);
/* Upload configuration */
$setting = C (' editor_upload ');
/* Call file Upload component to upload file */
$config = Array (
' MaxSize ' = 3145728,
' Savepath ' = './news/',
' Savename ' = = Array (' uniqid ', '),
' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '),
' Autosub ' = true,
' SubName ' = Array (' Date ', ' YMD '),
);
$this->uploader = new \think\upload ($config, ' Local ');
$info = $this->uploader->upload ($_files);
Log::write (Print_r ($info));
if ($info) {
$url = '/uploads '. $info [' imgfile '] [' Savepath ']. $info [' imgfile '] [' savename '];
$url = Str_replace ('./', '/', $url);
$info [' fullpath '] = __root__. $url;
}
Session (' Upload_error ', $this->uploader->geterror ());
return $info;
}
/**
* Upload Images
*/
Public Function uploadpicture () {
TODO: User logon detection
/* Return standard data */
$return = Array (' status ' = = 1, ' info ' = ' upload succeeded ', ' data ' = ');
$config = Array (
' MaxSize ' = 3145728,
' Savepath ' = './news/',
' Savename ' = = Array (' uniqid ', '),
' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '),
' Autosub ' = true,
' SubName ' = Array (' Date ', ' YMD '),
);
$this->uploader = new \think\upload ($config, ' Local ');
$info = $this->uploader->upload ($_files);
/* Record picture information */
if ($info) {
$url = '/uploads '. $info [' Download '] [' Savepath ']. $info [' Download '] [' savename '];
$url = Str_replace ('./', '/', $url);
$return [' path '] = __root__. $url;
$return [' id '] = 111;
$return [' status '] = 1;
$return = Array_merge ($info [' Download '], $return);
} else {
$return [' status '] = 0;
$return [' info '] = $this->uploader->geterror ();
}
/* Return JSON data */
$this->ajaxreturn ($return);
}
JS script, extract the first picture:
Get the first picture
$ (' #autolitpic '). Click (function () {
if ($ (this). attr (' checked ')) {
$ (this). attr (' checked ', false);
}else {
$ (this). attr (' checked ', true);
var content=$ ('. Content '). Val ();
if (Content.match (/src= "[^"]+ "/g) ==null) {
Alert (' article content is not picture ');
Return
}else{
var strcount=content.match (/src= "[^"]+ "/g) [0].replace (" Src=\ "", "");
var val=strcount.substring (0,strcount.length-1). Replace ("http://cb2013.tdedu.org", "" ");
$ ("#thumb_img"). attr (' src ', Val);
$ ("#img"). Val (Val);
}
}
});
Cancel thumbnail image
$ ('. Qximg '). Click (function () {
$ ("#thumb_img"). attr (' src ', ' ");
$ ("#img"). Val ("");
});
keditor_php image Upload