Welcome to the Linux community forum and interact with 2 million technical staff. Use CKEditor to upload images in php: The CKEditor source code package does not contain images and is uploaded to the server for file processing, the following is a script code written using PHP scripts to process uploaded files. No more security processing is performed, which is for your reference only. first, in the CKEditor confi
Welcome to the Linux community forum and interact with 2 million technical staff> Use CKEditor in php to upload images: The CKEditor source code package does not contain images and is uploaded to the server for file processing, the following is a script code written using PHP scripts to process uploaded files. No more security processing is performed, which is for your reference only. first, in the CKEditor confi
Welcome to the Linux community forum and interact with 2 million technicians>
Use CKEditor in php to upload images:
The CKEditor source code package does not contain images that are uploaded to the server for processing files. Below is a script code written using PHP scripts to process uploaded files, without more security processing, for reference only.
First, add the following code to the config. js file of CKEditor:
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 the address as needed.
The upload. php file is as follows:
$ 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 of 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 of the site.
$ Config ['site _ url'] = ""; // the website address. This parameter is related to the Image Upload address and cannot be left blank without adding "/".
// 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 and write permissions ");
}
}
}
// Output js call
Function mkhtml ($ fn, $ fileurl, $ message ){
$ Str ='