CKEditor's original package does not contain images uploaded to the server for file processing. another open-source product of CKEditor: CKFinder makes a good supplement. However, it is much easier to download the source code and configure it again. however, to upload images only, the entire FCKEditor must be used.
It took me one afternoon to write a script code for processing uploaded files using a PHP script. I didn't do more security processing and hoped it would be useful to everyone.
First, add the following code to your config. js file:
The code is as follows:
CKEDITOR. editorConfig = function (config)
{
Config. filebrowserImageUploadUrl = './upload. php? Type = img ';
Config. filebrowserFlashUploadUrl = './upload. php? Type = flash ';
};
The above configuration is the address of the file to be processed. you can modify it as needed. The upload. php file is as follows:
The code is as follows:
/*
CKEditor_upload.php
Monkee
*/
$ Config = array ();
$ Config ['type'] = array ("flash", "img"); // upload the allowed type value
$ Config ['IMG '] = array ("jpg", "bmp", "gif"); // img allows suffixes
$ Config ['Flash'] = array ("flv", "swf"); // flash allows suffixes
$ Config ['flash _ size'] = 200; // The maximum size of the uploaded flash is KB.
$ Config ['IMG _ size'] = 500; // The maximum size of uploaded img is KB.
$ Config ['message'] = "uploaded successfully"; // The message displayed after the upload is successful. if it is null, the message is not displayed.
$ Config ['name'] = mktime (); // the uploaded file naming rules are named in unix timestamps.
$ Config ['flash _ dir'] = "/ckeditor/upload/flash"; // upload The flash file address with an absolute address to facilitate upload. "/" is not added after the php file is placed in any location on the site "/"
$ Config ['IMG _ dir'] = "/ckeditor/upload/img"; // upload the imgfile address with an absolute address and an absolute address to facilitate upload. "/" is not added after the php file is placed in any location on the site "/"
$ Config ['site _ url'] = ""; // The website address. this parameter is related to the image upload address. "/" is left blank.
// File Upload
Uploadfile ();
Function uploadfile ()
{
Global $ config;
// Determine whether the call is illegal
If (empty ($ _ GET ['ckeditorfuncnum'])
Mkhtml (1, "", "incorrect function call request ");
$ Fn = $ _ GET ['ckeditorfuncnum'];
If (! In_array ($ _ GET ['type'], $ config ['type'])
Mkhtml (1, "", "incorrect file call request ");
$ Type = $ _ GET ['type'];
If (is_uploaded_file ($ _ FILES ['upload'] ['tmp _ name'])
{
// Determine whether a file is allowed to be uploaded
$ Filearr = pathinfo ($ _ FILES ['upload'] ['name']);
$ Filetype = $ filearr ["extension"];
If (! In_array ($ filetype, $ config [$ type])
Mkhtml ($ fn, "", "incorrect file type! ");
// Determine whether the file size meets the requirements
If ($ _ FILES ['upload'] ['size']> $ config [$ type. "_ size"] * 1024)
Mkhtml ($ fn, "", "the uploaded file cannot exceed". $ config [$ type. "_ size"]. "KB! ");
// $ Filearr = explode (".", $ _ FILES ['upload'] ['name']);
// $ Filetype = $ filearr [count ($ filearr)-1];
$ 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, "", "file Upload failed. Please check the upload directory settings and directory read/write permissions ");
}
}
}
// Output js call
Function mkhtml ($ fn, $ fileurl, $ message)
{
$ Str ='