CKEditor Upload image configuration PHP language

Source: Internet
Author: User
Tags configuration php
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. But you need to download the source code and then configure it...

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 more convenient to download the source code and then configure it. however, to upload images only, the entire system 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:

Reference content 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:

Reference content 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 ='

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.