Home >Backend Development >PHP Tutorial >CKEditor+CKFinder+php upload file configuration method_PHP tutorial

CKEditor+CKFinder+php upload file configuration method_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:56:03915browse

CKEditor+CKFinder+php upload file configuration method, the new version of CKEditor only provides basic text editing functions, and the upload module consists of another component, CKFinder. Here we mainly record some parameter configurations uploaded by CKFinder, which can successfully upload files, customize the uploaded file directory, and rename files by date + random characters.

The new version of CKEditor only provides basic text editing functions, and the upload module is provided by another component, CKFinder. Here we mainly record some parameter configurations uploaded by CKFinder, which can successfully upload files, customize the uploaded file directory, and rename files by date + random characters.

1. Download CKFinder.
Download CKFinder, unzip and put it in the same directory as CKEditor, download address: http://ckfinder.com/

2. Enable the upload function.
Open the ckfinder\config.php file, find the function CheckAuthentication(), about line 21, change the last line return false; to return true;

3. Customize the upload file directory.
Open the ckfinder\config.php file and set the variable $baseUrl = '/upload/';, about line 63.

4. Set up the upload subdirectory to be generated by date.
If your website uploads a lot of files and the files are all in one directory, you may not be very concerned about file performance. In this case, we will generate the directory in the format of /upload/yyyy/mm/. Open the ckfinder\config.php file and find $config['ResourceType'][], about line 189, between 'url' => $baseUrl . 'files' and 'directory' => $baseDir . 'files' Add . '/' . date("Y") . '/' . date("m"), as well as other Images and Flash items. The url here represents the address returned to the input box after uploading, and directory represents the directory of the uploaded file.

5. Rename the uploaded file by date + random characters.
This can support file uploads with Chinese names. Open the ckfinder\core\connector\php\php5\CommandHandler\FileUpload.php file and add a generate file name function at the end of the file

for ($x = 0; $x < 5; $x++) {            $rand .= substr($string, mt_rand(0, strlen($string) - 1), 1);
The code is as follows
 代码如下 复制代码

function mySetFileName() {
    $gettime = explode(' ', microtime());
    $string = 'abcdefghijklmnopgrstuvwxyz0123456789';
    $rand = '';

    for ($x = 0; $x < 5; $x++) {
        $rand .= substr($string, mt_rand(0, strlen($string) - 1), 1);
    }

    return date("ymdHis") . substr($gettime[0], 2, 6) . $rand;
}

Copy code

 代码如下 复制代码
if ($sFileName != $sUnsafeFileName) {
    $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
}
function mySetFileName() {

$gettime = explode(' ', microtime());
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';

$rand = '';
 代码如下 复制代码
$sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
$sFileName = mySetFileName() . '.' . $sExtension;
}

return date("ymdHis") . substr($gettime[0], 2, 6) . $rand;

} Look for the code below, about line 63,
The code is as follows Copy code
if ($sFileName != $sUnsafeFileName) { $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED; }
Add the following code below,
The code is as follows Copy code
$sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName ); $sFileName = mySetFileName() . '.' . $sExtension; http://www.bkjia.com/PHPjc/632195.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632195.htmlTechArticleCKEditor+CKFinder+php upload file configuration method, the new version of CKEditor only provides basic text editing functions, upload The module consists of another component CKFinder. Here we mainly record what CKFinder uploaded...
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