html:
//後台代碼
//keditor編輯器上傳圖片處理
public function ke_upimg(){
/* 返回標準資料*/
=> '');
$img = $this->upload();
/* 記錄附件資訊*/
img['fullpath'];
unset($return['info'], $return['data']);
} else { $return['message'] = session('upload_error') ;
}
/* 回傳JSON資料*/
/* 上傳圖片*/
public function upload(){
session('upload_error', null);
/* 上傳設定*/
$setting = C('EDITOR_UPLOAD');
$config = array(
'maxSize' => 3145728,
'./news/',
'saveName' => array('uniqid',''),
' autoSub' => true,
'subName' => array('date','Ymd'),
);
$info = $this ->uploader->upload($_FILES);
//Log::write(print_r($info));
if($info 'savepath'].$info['imgFile']['savename'];
$url = str_replace('./', '/', $url); ;
}
session('upload_error', $this-p info;
}
/**
* 上傳圖片
*/
public function uploadPicture(){
public function uploadPicture(){
/TODO: 使用者登入偵測
/* 傳回標準資料*/
$return = array('status' => 1, 'info' => '上傳成功', 'data' = '' $config = array(
'maxSize' => 3145728,
'saveName' => array('uniqid',''),
'exts' => array('jpg ', 'gif', 'png', 'jpeg'),
'autoSub' => true,
);
$this->uploader = new ThinkUpload($config, 'Local');
$info = $this->uploader->upload($_FILES);
/* 記錄圖片資訊*/
if($info){
發現$$
$url = str_replace('./', '/', $url);
'id'] = 111;
$return['status '] = 1;
$return = array_merge($info['download'], $return);
$return['info'] = $this- >uploader->getError();
}
/* 回傳JSON資料*/
js腳本,擷取第一張圖片:
$('#autolitpic').click(function (){
if($(this).attr('checked')){,false);
}else { $(this).attr('checked',true);
[^"]+"/g)==null){
alert('文章內容無圖片');
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);
}
}
});
//取消縮短略圖
$('.qximg').click(function (){
$("#thumb_img").attr('src',"");
$("#img").val("");
});