I spent an afternoon writing a script for processing uploaded files using a PHP script. Code , No more security measures, and hope to be useful to everyone.
First, add the following code to your Config. js file:
Copy code 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: Copy code The Code is as follows: <? PHP
/*
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 = '<SCRIPT type = "text/JavaScript"> window. parent. ckeditor. tools. callfunction ('. $ fn. ',\''. $ fileurl. '\',\''. $ message. '\'); </SCRIPT> ';
Exit ($ Str );
}
?>
Package and download code