Home  >  Article  >  Backend Development  >  CKEditor image upload configuration PHP language file_PHP tutorial

CKEditor image upload configuration PHP language file_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:55:48739browse

Bangkejia (www.Bkjia.com) tutorial The original package of CKEditor does not include the upload server-side processing file of the image. Another open source product of the company: CKFinder makes a good supplement. But it is much more convenient to download the source code and then configure it, but it is a bit overkill to use such a large system just to upload pictures. I spent an afternoon writing it myself using a PHP script. A script code for processing uploaded files without doing more security processing. I hope it will be useful to everyone.

First, add the following code to your config.js file:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] CKEDITOR.editorConfig = function( config )
{
config.filebrowserImageUploadUrl = './upload.php?type=img';
config.filebrowserFlashUploadUrl = './upload.php?type=flash';
};

The above configuration is the address of the uploaded file to be processed. You can modify it according to your own situation. The upload.php file is as follows:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] /*
CKEditor_upload.php
monkee
2009-11-15 16:47
*/
$config=array();

$config['type']=array("flash","img"); //Upload allowed type values

$config['img']=array("jpg","bmp", "gif"); //img allows suffix
$config['flash']=array("flv","swf"); //flash allows suffix

$config['flash_size'] =200; //The upper limit unit for uploading flash size: KB
$config['img_size']=500; //The upper limit unit for uploading img size: KB

$config['message']="Upload Success"; //The message displayed after the upload is successful. If it is empty, it will not be displayed.

$config['name']=mktime(); //The file naming rules after uploading are based on unix timestamp. Naming

$config['flash_dir']="/ckeditor/upload/flash"; //The upload flash file address uses an absolute address for convenience. The upload.php file can be placed anywhere in the site without adding "/" after it.
$config['img_dir']="/ckeditor/upload/img"; //Upload the img file address using an absolute address. Using an absolute address is convenient. Place the upload.php file anywhere in the site without adding "/" at the end.

$config['site_url']=""; //The URL of the website is related to the address after the image is uploaded. Do not add "/" at the end and can leave it blank

//File upload
uploadfile();

function uploadfile()
{
global $config;
//Determine whether it is an illegal call
if(empty($_GET['CKEditorFuncNum'] ))
mkhtml(1,"","Bad function call request");
$fn=$_GET['CKEditorFuncNum'];
if(!in_array($_GET['type'] ,$config['type']))
mkhtml(1,"","Bad file call request");
$type=$_GET['type'];
if(is_uploaded_file( $_FILES['upload']['tmp_name']))
{
//Determine whether uploading files is allowed
$filearr=pathinfo($_FILES['upload']['name']);
$filetype=$filearr["extension"];
if(!in_array($filetype,$config[$type]))
mkhtml($fn,"","Wrong file type! ");
//Judge 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='';
exit($str);
}
?>

Author’s blog: http://www.cnblogs.com/monkee/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364387.htmlTechArticleThe original package of LieHuo.Net tutorial CKEditor does not contain the upload server-side processing file of the image. Another open source product of the company: CKFinder makes a good complement. But to download...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn