[PHP] getimagesize,ckeditor大小設定
ckeditor的編輯器大小可以在config.js設定config.width = '100%';
要來判定上傳的是不是圖片可以使用 getimagesize 這個function
當上傳的並非是圖片時會 return false
上傳成功後會回傳一個array
index 0 : 圖片width
index 1 : 圖片height
剩下的請參考官方manual
附上ckeditor內上傳圖片相關code
首先必須將text area的id給取得,之後再該text area上蓋一層div
其中Store_Info為textarea的id
filebrowserImageUploadUrl則是server-side code處理上傳圖片用
要來判定上傳的是不是圖片可以使用 getimagesize 這個function
當上傳的並非是圖片時會 return false
上傳成功後會回傳一個array
index 0 : 圖片width
index 1 : 圖片height
剩下的請參考官方manual
附上ckeditor內上傳圖片相關code
首先必須將text area的id給取得,之後再該text area上蓋一層div
$(document).ready(function(){
CKEDITOR.replace('Store_Info', { filebrowserImageUploadUrl: '上傳圖片的php-code'});
for (var i in CKEDITOR.instances) {
CKEDITOR.instances[i].on('focus', function() {
if (!is_beforeunload) {
is_beforeunload = true;
$(window).bind('beforeunload', function (e) {
return '資料尚未存檔,確定是否要離開?';
});
}
});
}
});
其中Store_Info為textarea的id
filebrowserImageUploadUrl則是server-side code處理上傳圖片用
/*
* 新增供應商詳細說明圖片的上傳controller
* */
public function upload_supplier_detail_pic(){
// ckeditor回傳的參數
$CKEditorFuncNum = $this->input->get('CKEditorFuncNum', true);
// 檔案存放路徑
$file_path = I_DOC."/store_supplier_detail";
// 前台顯示網址
$show_path = SERVER_ROOT.'/assets/img/store_supplier_detail';
// 有檔案上傳
if(isset($_FILES['upload']["tmp_name"]) && strlen($_FILES['upload']["tmp_name"]) > 0){
//確認是否上傳圖片
$check = getimagesize($_FILES["upload"]["tmp_name"]);
if($check !== false){
if($check[0] <= 700){
$ext = strtolower(strrchr($_FILES['upload']["name"],'.'));
$file_new_name = date('YmdHis').$ext;
move_uploaded_file($_FILES['upload']["tmp_name"],$file_path.'/'.$file_new_name);
echo '';
}else{
echo '';
}
}else{
echo '';
}
}
}
留言
張貼留言