CKEDITOR 上傳圖片~


找到 CKEditor 的 config.js

加入這一行
config.filebrowserImageUploadUrl = './ckupload.php?type=img';


我的整個 config.js 設定檔變成了:

CKEDITOR.editorConfig = function( config )
{
config.height = 600;
config.filebrowserImageUploadUrl = './ckupload.php?type=img';
};

-----------------------------------------
YES 看的出來了吧!!! 必需要做一隻 ckupload.php 的PHP程式來接收圖片喔.


$config=array();
$config['type']=array("flash","img"); //上傳允許類型
$config['img']=array("jpg","bmp","gif"); //img允許檔案類別
$config['flash']=array("flv","swf"); //flash允許檔案類別
$config['flash_size']=200; //上傳flash大小上限制大小 200KB
$config['img_size']=500; //上傳img大小上限制大小 500KB
$config['message']="upload success";
$config['name']=mktime(); //上傳文件命名方式, 用時間.
$config['flash_dir']="/www/image/ckimg"; //上傳flash文件路徑
$config['img_dir'] ="/www/image/ckimg"; //上傳img文件路徑
$config['site_url']="http://www.linuxuser.com.tw"; //URL

uploadfile();
function uploadfile() {
global $config;

if(empty($_GET['CKEditorFuncNum']))
mkhtml(1,"","檔案類型不正確");

$fn=$_GET['CKEditorFuncNum'];

if(!in_array($_GET['type'],$config['type']))
mkhtml(1,"","檔案類型不正確");

$type=$_GET['type'];

if(is_uploaded_file($_FILES['upload']['tmp_name'])) {
$filearr=pathinfo($_FILES['upload']['name']);
$filetype=$filearr["extension"];

if(!in_array($filetype,$config[$type]))
mkhtml($fn,"","請檢查的文件類型!"); //判?文件大小是否符合要求
if($_FILES['upload']['size']>$config[$type."_size"]*1024)
mkhtml($fn,"","上傳的文件不能超過".$config[$type."_size"]."KB!");
$file_abso=$config[$type."_dir"]."/".$config['name'].".".$filetype;
$file_host=$_SERVER['DOCUMENT_ROOT'].$file_abso;

if(move_uploaded_file($_FILES['upload']['tmp_name'],$file_host)) {
mkhtml($fn,$config['site_url'].$file_abso,$config['message']);
} else {
mkhtml($fn,"","請檢查目錄權限");
}
}
}

function mkhtml($fn,$fileurl,$message) {
$str='';
exit($str);
}

?>


大功告成~ 超讚~

peeress 發表在 痞客邦 PIXNET 留言(0) 人氣()