CKEditor integrates ckfinder to upload images. After half a day, the CKEditor was finally made clear, and with ckfinder, the image was uploaded. the specific steps were given to the comrades in need. 1. after setting up the ckeditor project, decompress the ckeditor and ckfinder for half a day, and finally make the CKEditor clear, and use ckfinder to upload images. the specific steps are provided to the comrades in need. 1. create a project ckeditor and decompress ckeditor and ckfinder to the project.
The two items are as follows:
Ckeditor: http://ckeditor.com/download/
Ckfinder: http://ckfinder.com/download
The project directory structure is as follows:
Ckeditor
--- Ckeditor
-- Ckfinder
-- Php file used for testing
2. find the config. php file in the ckfinder directory and open it.
1) locate the CheckAuthentication method. by default, this method only returns false. Therefore, files are not allowed to be uploaded to the server and must be modified. the function must be noted in English, it is not recommended to change it to false directly, because it will be insecure and everything will be uploaded. Therefore, the following figure shows how to use session to handle it.
The code is as follows: |
|
Session_start (); Function CheckAuthentication () { If (isset ($ _ SESSION ['useeditor']) // you can name it as needed. Return true; Else Return false; } |
2) configure the Upload file location,
By default, ckfinder stores the uploaded files in the ckfinder/userfiles/images folder under the root directory. you can change the files to your own project directory and create an upfiles folder under the project. in php, find the baseUrl and modify it:
The code is as follows: |
|
$ BaseUrl = '/ckeditor/upfiles /'; |
In this way, the uploaded files will be saved to the images folder under upfiles. Of course, you can also set different Upload folders as needed. As for how to pass the value to him to determine the upload folder, of course, it is through session.
3. modify the Upload file name. by default, the system will name the file with the original name, so we will rename the file. Method: Open the FileUpload. php file under ckfindercoreconnectorphpphp5CommandHandler.
Find $ sUnsafeFileName and add the renaming code, as shown below:
The code is as follows: |
|
$ SUnsafeFileName = CKFinder_Connector_Utils_FileSystem: convertToFilesystemEncoding (CKFinder_Connector_Utils_Misc: mbBasename ($ uploadedFile ['name']); // Obtain the original file suffix first $ SExtension = CKFinder_Connector_Utils_FileSystem: getExtension ($ sUnsafeFileName ); // Rename the file $ SUnsafeFileName = date ('ymdhis ').'. '. $ sExtension; |
4. use ckfinder in test. php. the code is as follows:
The code is as follows: |
|
Session_start (); $ _ SESSION ['useeditor'] = 'OK'; // do not forget this; otherwise, you cannot upload it. Include_once ('ckeditor/ckeditor. php '); Include_once ('ckfinder/ckfinder. php '); $ Fc = new CKEditor (); CKFinder: SetupCKEditor ($ fc, './ckfinder /'); $ Fc-> editor ("content "," Initial value. "); |
Bytes. 1. create a project ckeditor and decompress ckeditor and ckfinder...