ckedit4 does not have a picture upload function. We can set the image upload interface through configuration files, and then combine it with the backend program to achieve picture upload. This article explains how CKEditor4 combines PHP to implement the uploading function.
Configuration File
turn upckeditor
In the directoryFile, add two configurations
= 'uploadimage' = '/api/UploadImg/' //filebrowserImageUploadUrl Replace with the interface you need to upload
When we clicked the picture button, we found that there were more uploads in the pop-up windowtag
The interface has a select file button inside, which can upload images to the server, that is, the file file will be sent to the filebrowserImageUploadUrl interface set above.
Backend processing files
TIPS:
1. The json file that needs to be returned by ckedit4 handles subsequent operations, using json_encode;
2. $_REQUEST["ckCsrfToken"] is required by ckedit4;
3. File format verification and file size processing were performed;
4. The file name is uniquely processed.
<?php $callback = $_REQUEST["ckCsrfToken"]; $list=array("uploaded"=>'0','callback'=>$callback); $upaddress = "/uploads/allimg/".strftime("%Y%m",time())."/"; echo upload(); function upload(){ global $list,$upaddress; $callback = $_REQUEST["ckCsrfToken"]; $extensions = array("jpg","bmp","gif","png"); $allowed_types = ['image/jpeg', 'image/png', 'image/gif']; $uploadFilename = $_FILES['upload']['name']; $uploadFilesize = $_FILES['upload']['size']; $uploadFiletype = $_FILES['upload']['type']; $extension = pathInfo($uploadFilename,PATHINFO_EXTENSION); if(is_uploaded_file($_FILES['upload']['tmp_name']) && $uploadFilesize < 1024*300 && in_array($uploadFiletype, $allowed_types) && in_array($extension,$extensions)){ $uploadPath = $_SERVER['DOCUMENT_ROOT'].$upaddress; if(!file_exists($uploadPath)) { mkdir($uploadPath,0777,true); } $uuid = str_replace('.','',uniqid("",TRUE)).".".$extension; $desname = $uploadPath.$uuid; $tag = move_uploaded_file($_FILES['upload']['tmp_name'],$desname); $list['uploaded']=1; $list['fileName']=$uuid; $list['url']=$upaddress.$uuid; return json_encode($list); }else{ $list['error']="The file type is wrong or the file is too large!"; return json_encode($list); } } ?>
Summarize
This is the article about CKEditor4 combining PHP to implement the uploading function of uploading images. For more related content related to CKEditor4, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!