Пример #1
0
 /**
  * Throw file upload error, return true if error has been thrown, false if error has been catched
  *
  * @param int $number
  * @param string $text
  * @access public
  */
 function throwError($number, $uploaded = false, $exit = true)
 {
     if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
         return false;
     }
     $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $sFileName = $oRegistry->get("FileUpload_fileName");
     $sFileUrl = $oRegistry->get("FileUpload_url");
     header('Content-Type: text/html; charset=utf-8');
     $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
     if (!$uploaded) {
         $sFileName = "";
     }
     if (!empty($_GET['response_type']) && $_GET['response_type'] == 'txt') {
         echo $sFileName . "|" . $errorMessage;
         exit;
     }
     echo "<script type=\"text/javascript\">";
     if (!empty($_GET['CKFinderFuncNum'])) {
         $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
         if (!$uploaded) {
             $sFileUrl = "";
             $sFileName = "";
         }
         $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']);
         echo "window.parent.CKFinder.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "');";
     } else {
         echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
     }
     echo "</script>";
     if ($exit) {
         exit;
     }
 }
Пример #2
0
 /**
  * Throw file upload error, return true if error has been thrown, false if error has been catched
  *
  * @param int $number
  * @param string $text
  * @access public
  */
 function throwError($number, $uploaded = false, $exit = true)
 {
     if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
         return false;
     }
     $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $sFileName = $oRegistry->get("FileUpload_fileName");
     $sFileUrl = $oRegistry->get("FileUpload_url");
     header('Content-Type: text/html; charset=utf-8');
     /**
      * echo <script> is not called before CKFinder_Connector_Utils_Misc::getErrorMessage
      * because PHP has problems with including files that contain BOM character.
      * Having BOM character after <script> tag causes a javascript error.
      */
     echo "<script type=\"text/javascript\">";
     if (!empty($_GET['CKEditor'])) {
         $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
         if (!$uploaded) {
             $sFileUrl = "";
             $sFileName = "";
         }
         $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
         echo "window.parent.CKEDITOR.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "');";
     } else {
         if (!$uploaded) {
             echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
         } else {
             echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
         }
     }
     echo "</script>";
     if ($exit) {
         exit;
     }
 }
Пример #3
0
 function __construct($thumbnailsNode)
 {
     if (extension_loaded('gd') && isset($thumbnailsNode['enabled'])) {
         $this->_isEnabled = CKFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['enabled']);
     }
     if (isset($thumbnailsNode['maxWidth'])) {
         $_maxWidth = intval($thumbnailsNode['maxWidth']);
         if ($_maxWidth >= 0) {
             $this->_maxWidth = $_maxWidth;
         }
     }
     if (isset($thumbnailsNode['maxHeight'])) {
         $_maxHeight = intval($thumbnailsNode['maxHeight']);
         if ($_maxHeight >= 0) {
             $this->_maxHeight = $_maxHeight;
         }
     }
     if (isset($thumbnailsNode['quality'])) {
         $_quality = intval($thumbnailsNode['quality']);
         if ($_quality > 0 && $_quality <= 100) {
             $this->_quality = $_quality;
         }
     }
     if (isset($thumbnailsNode['url'])) {
         $this->_url = $thumbnailsNode['url'];
     }
     if (isset($thumbnailsNode['directory'])) {
         $this->_directory = $thumbnailsNode['directory'];
     }
 }
Пример #4
0
 /**
  * Throw file upload error, return true if error has been thrown, false if error has been catched
  *
  * @param int $number
  * @param string $text
  * @access public
  */
 public function throwError($number, $uploaded = false, $exit = true)
 {
     if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
         return false;
     }
     $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $sFileName = $oRegistry->get("FileUpload_fileName");
     $sFileUrl = $oRegistry->get("FileUpload_url");
     $sEncodedFileName = CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sFileName);
     $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sEncodedFileName);
     if (!empty($_GET['responseType']) && $_GET['responseType'] == 'json') {
         header('Content-Type: application/json; charset=utf-8');
         $data = array('fileName' => $sEncodedFileName, 'uploaded' => (int) $uploaded);
         if ($uploaded) {
             $data['url'] = $sFileUrl . CKFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName);
         }
         if ($number !== CKFINDER_CONNECTOR_ERROR_NONE) {
             $data['error'] = array('number' => $number, 'message' => $errorMessage);
         }
         echo json_encode($data);
     } else {
         header('Content-Type: text/html; charset=utf-8');
         /**
          * echo <script> is not called before CKFinder_Connector_Utils_Misc::getErrorMessage
          * because PHP has problems with including files that contain BOM character.
          * Having BOM character after <script> tag causes a javascript error.
          */
         echo "<script type=\"text/javascript\">";
         if (!empty($_GET['CKEditor'])) {
             if (!$uploaded) {
                 $sFileUrl = "";
                 $sFileName = "";
                 $sEncodedFileName = "";
             }
             $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
             echo "window.parent.CKEDITOR.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . CKFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName)) . "', '" . str_replace("'", "\\'", $errorMessage) . "');";
         } else {
             if (!$uploaded) {
                 echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
             } else {
                 echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . CKFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName)) . "', '" . str_replace("'", "\\'", $sEncodedFileName) . "', '') ;";
             }
         }
         echo "</script>";
     }
     if ($exit) {
         exit;
     }
 }
Пример #5
0
 function __construct($accessControlNodes)
 {
     foreach ($accessControlNodes as $node) {
         $_folderView = isset($node['folderView']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['folderView']) : false;
         $_folderCreate = isset($node['folderCreate']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['folderCreate']) : false;
         $_folderRename = isset($node['folderRename']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['folderRename']) : false;
         $_folderDelete = isset($node['folderDelete']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['folderDelete']) : false;
         $_fileView = isset($node['fileView']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['fileView']) : false;
         $_fileUpload = isset($node['fileUpload']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['fileUpload']) : false;
         $_fileRename = isset($node['fileRename']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['fileRename']) : false;
         $_fileDelete = isset($node['fileDelete']) ? CKFinder_Connector_Utils_Misc::booleanValue($node['fileDelete']) : false;
         $_role = isset($node['role']) ? $node['role'] : "*";
         $_resourceType = isset($node['resourceType']) ? $node['resourceType'] : "*";
         $_folder = isset($node['folder']) ? $node['folder'] : "/";
         $this->addACLEntry($_role, $_resourceType, $_folder, array($_folderView ? CKFINDER_CONNECTOR_ACL_FOLDER_VIEW : 0, $_folderCreate ? CKFINDER_CONNECTOR_ACL_FOLDER_CREATE : 0, $_folderRename ? CKFINDER_CONNECTOR_ACL_FOLDER_RENAME : 0, $_folderDelete ? CKFINDER_CONNECTOR_ACL_FOLDER_DELETE : 0, $_fileView ? CKFINDER_CONNECTOR_ACL_FILE_VIEW : 0, $_fileUpload ? CKFINDER_CONNECTOR_ACL_FILE_UPLOAD : 0, $_fileRename ? CKFINDER_CONNECTOR_ACL_FILE_RENAME : 0, $_fileDelete ? CKFINDER_CONNECTOR_ACL_FILE_DELETE : 0), array($_folderView ? 0 : CKFINDER_CONNECTOR_ACL_FOLDER_VIEW, $_folderCreate ? 0 : CKFINDER_CONNECTOR_ACL_FOLDER_CREATE, $_folderRename ? 0 : CKFINDER_CONNECTOR_ACL_FOLDER_RENAME, $_folderDelete ? 0 : CKFINDER_CONNECTOR_ACL_FOLDER_DELETE, $_fileView ? 0 : CKFINDER_CONNECTOR_ACL_FILE_VIEW, $_fileUpload ? 0 : CKFINDER_CONNECTOR_ACL_FILE_UPLOAD, $_fileRename ? 0 : CKFINDER_CONNECTOR_ACL_FILE_RENAME, $_fileDelete ? 0 : CKFINDER_CONNECTOR_ACL_FILE_DELETE));
     }
 }
Пример #6
0
 /**
  * Throw file upload error, return true if error has been thrown, false if error has been catched
  *
  * @param int $number
  * @param string $text
  * @access public
  */
 public function throwError($number, $uploaded = false, $exit = true)
 {
     if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
         return false;
     }
     $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $sFileName = $oRegistry->get("FileUpload_fileName");
     header('Content-Type: text/html; charset=utf-8');
     $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
     if (!$uploaded) {
         $sFileName = "";
     }
     echo "<script type=\"text/javascript\">";
     echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
     echo "</script>";
     if ($exit) {
         exit;
     }
 }
Пример #7
0
 /**
  * Load values from config
  *
  * @access private
  */
 private function loadValues()
 {
     if (function_exists('CheckAuthentication')) {
         $this->_isEnabled = CheckAuthentication();
     }
     if (isset($GLOBALS['config']['LicenseName'])) {
         $this->_licenseName = (string) $GLOBALS['config']['LicenseName'];
     }
     if (isset($GLOBALS['config']['LicenseKey'])) {
         $this->_licenseKey = (string) $GLOBALS['config']['LicenseKey'];
     }
     if (isset($GLOBALS['config']['FilesystemEncoding'])) {
         $this->_filesystemEncoding = (string) $GLOBALS['config']['FilesystemEncoding'];
     }
     if (isset($GLOBALS['config']['RoleSessionVar'])) {
         $this->_roleSessionVar = (string) $GLOBALS['config']['RoleSessionVar'];
     }
     if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
         $this->_checkDoubleExtension = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
     }
     if (isset($GLOBALS['config']['DisallowUnsafeCharacters'])) {
         $this->_disallowUnsafeCharacters = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['DisallowUnsafeCharacters']);
     }
     if (isset($GLOBALS['config']['SecureImageUploads'])) {
         $this->_secureImageUploads = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
     }
     if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) {
         $this->_checkSizeAfterScaling = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']);
     }
     if (isset($GLOBALS['config']['ForceAscii'])) {
         $this->_forceAscii = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['ForceAscii']);
     }
     if (isset($GLOBALS['config']['HtmlExtensions'])) {
         $this->_htmlExtensions = (array) $GLOBALS['config']['HtmlExtensions'];
     }
     if (isset($GLOBALS['config']['HideFolders'])) {
         $this->_hideFolders = (array) $GLOBALS['config']['HideFolders'];
     }
     if (isset($GLOBALS['config']['HideFiles'])) {
         $this->_hideFiles = (array) $GLOBALS['config']['HideFiles'];
     }
     if (isset($GLOBALS['config']['ChmodFiles'])) {
         $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
     }
     if (isset($GLOBALS['config']['ChmodFolders'])) {
         $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
     }
     if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
         $_defaultResourceTypes = (string) $GLOBALS['config']['DefaultResourceTypes'];
         if (strlen($_defaultResourceTypes)) {
             $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
         }
     }
     if (isset($GLOBALS['config']['TempDirectory'])) {
         $this->_tempDirectory = $GLOBALS['config']['TempDirectory'];
     }
     if (isset($GLOBALS['config']['XSendfile'])) {
         $this->_xsendfile = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['XSendfile']);
     }
     if (isset($GLOBALS['config']['XSendfileNginx'])) {
         $this->_xsendfileNginx = (array) $GLOBALS['config']['XSendfileNginx'];
     }
 }
Пример #8
0
 * Handle FileUpload command

 *

 * @package CKFinder

 * @subpackage CommandHandlers

 * @copyright CKSource - Frederico Knabben

 */
class CKFinder_Connector_CommandHandler_FileUpload extends CKFinder_Connector_CommandHandler_CommandHandlerBase
{
    /**

     * Command name

     *

     * @access protected

     * @var string

     */
    protected $command = "FileUpload";
    /**

     * send response (save uploaded file, resize if required)

     * @access public

     *

     */
    public function sendResponse()
    {
        $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE;
        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
        $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
        $oRegistry->set("FileUpload_fileName", "unknown file");
        $uploadedFile = array_shift($_FILES);
        if (!isset($uploadedFile['name'])) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID);
        }
        $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name']));
        $sFileName = CKFinder_Connector_Utils_FileSystem::secureFileName($sUnsafeFileName);
        if ($sFileName != $sUnsafeFileName) {
            $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
        }
        $oRegistry->set("FileUpload_fileName", $sFileName);
        $this->checkConnector();
        $this->checkRequest();
        if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
        }
        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
        if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
        }
        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
        if (!$resourceTypeInfo->checkExtension($sFileName)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
        }
        $oRegistry->set("FileUpload_fileName", $sFileName);
        $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
        $maxSize = $resourceTypeInfo->getMaxSize();
        if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
        }
        $htmlExtensions = $_config->getHtmlExtensions();
        $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
        if ($htmlExtensions && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
        }
        $secureImageUploads = $_config->getSecureImageUploads();
        if ($secureImageUploads && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
        }
        switch ($uploadedFile['error']) {
            case UPLOAD_ERR_OK:
                break;
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
                break;
            case UPLOAD_ERR_PARTIAL:
            case UPLOAD_ERR_NO_FILE:
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
                break;
            case UPLOAD_ERR_CANT_WRITE:
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
                break;
            case UPLOAD_ERR_EXTENSION:
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
                break;
        }
        $sServerDir = $this->_currentFolder->getServerPath();
        while (true) {
            $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
            if (file_exists($sFilePath)) {
                $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($sServerDir, $sFileName);
                $oRegistry->set("FileUpload_fileName", $sFileName);
                $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
            } else {
                if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
                    $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
                    } else {
                        if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
                            @unlink($sFilePath);
                            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                        }
                    }
                }
Пример #9
0
 /**
  * Get ResourceType configuration
  *
  * @param string $resourceTypeNode
  * @return array
  *
  */
 function __construct($resourceTypeNode)
 {
     if (isset($resourceTypeNode["name"])) {
         $this->_name = $resourceTypeNode["name"];
     }
     if (isset($resourceTypeNode["url"])) {
         $this->_url = $resourceTypeNode["url"];
     }
     if (!strlen($this->_url)) {
         $this->_url = "/";
     } else {
         if (substr($this->_url, -1, 1) != "/") {
             $this->_url .= "/";
         }
     }
     if (isset($resourceTypeNode["maxSize"])) {
         $this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string) $resourceTypeNode["maxSize"]);
     }
     if (isset($resourceTypeNode["directory"])) {
         $this->_directory = $resourceTypeNode["directory"];
     }
     if (!strlen($this->_directory)) {
         $this->_directory = resolveUrl($this->_url);
     }
     if (isset($resourceTypeNode["allowedExtensions"])) {
         if (is_array($resourceTypeNode["allowedExtensions"])) {
             foreach ($resourceTypeNode["allowedExtensions"] as $e) {
                 $this->_allowedExtensions[] = strtolower(trim((string) $e));
             }
         } else {
             $resourceTypeNode["allowedExtensions"] = trim((string) $resourceTypeNode["allowedExtensions"]);
             if (strlen($resourceTypeNode["allowedExtensions"])) {
                 $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
                 foreach ($extensions as $e) {
                     $this->_allowedExtensions[] = strtolower(trim($e));
                 }
             }
         }
     }
     if (isset($resourceTypeNode["deniedExtensions"])) {
         if (is_array($resourceTypeNode["deniedExtensions"])) {
             foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
                 $this->_deniedExtensions[] = strtolower(trim((string) $e));
             }
         } else {
             $resourceTypeNode["deniedExtensions"] = trim((string) $resourceTypeNode["deniedExtensions"]);
             if (strlen($resourceTypeNode["deniedExtensions"])) {
                 $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
                 foreach ($extensions as $e) {
                     $this->_deniedExtensions[] = strtolower(trim($e));
                 }
             }
         }
     }
 }
Пример #10
0
 /**
  * Create thumbnail
  *
  * @param string $sourceFile
  * @param string $targetFile
  * @param int $maxWidth
  * @param int $maxHeight
  * @param boolean $preserverAspectRatio
  * @param boolean $bmpSupported
  * @return boolean
  * @static
  * @access public
  */
 public static function createThumb($sourceFile, $targetFile, $maxWidth, $maxHeight, $quality, $preserverAspectRatio, $bmpSupported = false)
 {
     $sourceImageAttr = @getimagesize($sourceFile);
     if ($sourceImageAttr === false) {
         return false;
     }
     $sourceImageWidth = isset($sourceImageAttr[0]) ? $sourceImageAttr[0] : 0;
     $sourceImageHeight = isset($sourceImageAttr[1]) ? $sourceImageAttr[1] : 0;
     $sourceImageMime = isset($sourceImageAttr["mime"]) ? $sourceImageAttr["mime"] : "";
     $sourceImageBits = isset($sourceImageAttr["bits"]) ? $sourceImageAttr["bits"] : 8;
     $sourceImageChannels = isset($sourceImageAttr["channels"]) ? $sourceImageAttr["channels"] : 3;
     if (!$sourceImageWidth || !$sourceImageHeight || !$sourceImageMime) {
         return false;
     }
     $iFinalWidth = $maxWidth == 0 ? $sourceImageWidth : $maxWidth;
     $iFinalHeight = $maxHeight == 0 ? $sourceImageHeight : $maxHeight;
     if ($sourceImageWidth <= $iFinalWidth && $sourceImageHeight <= $iFinalHeight) {
         if ($sourceFile != $targetFile) {
             copy($sourceFile, $targetFile);
         }
         return true;
     }
     if ($preserverAspectRatio) {
         // Gets the best size for aspect ratio resampling
         $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight);
     } else {
         $oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight);
     }
     CKFinder_Connector_Utils_Misc::setMemoryForImage($sourceImageWidth, $sourceImageHeight, $sourceImageBits, $sourceImageChannels);
     switch ($sourceImageAttr['mime']) {
         case 'image/gif':
             if (@imagetypes() & IMG_GIF) {
                 $oImage = @imagecreatefromgif($sourceFile);
             } else {
                 $ermsg = 'GIF images are not supported';
             }
             break;
         case 'image/jpeg':
             if (@imagetypes() & IMG_JPG) {
                 $oImage = @imagecreatefromjpeg($sourceFile);
             } else {
                 $ermsg = 'JPEG images are not supported';
             }
             break;
         case 'image/png':
             if (@imagetypes() & IMG_PNG) {
                 $oImage = @imagecreatefrompng($sourceFile);
             } else {
                 $ermsg = 'PNG images are not supported';
             }
             break;
         case 'image/wbmp':
             if (@imagetypes() & IMG_WBMP) {
                 $oImage = @imagecreatefromwbmp($sourceFile);
             } else {
                 $ermsg = 'WBMP images are not supported';
             }
             break;
         case 'image/bmp':
             /*
              * This is sad that PHP doesn't support bitmaps.
              * Anyway, we will use our custom function at least to display thumbnails.
              * We'll not resize images this way (if $sourceFile === $targetFile),
              * because user defined imagecreatefrombmp and imagecreatebmp are horribly slow
              */
             if ($bmpSupported && @imagetypes() & IMG_JPG && $sourceFile != $targetFile) {
                 $oImage = CKFinder_Connector_Utils_Misc::imageCreateFromBmp($sourceFile);
             } else {
                 $ermsg = 'BMP/JPG images are not supported';
             }
             break;
         default:
             $ermsg = $sourceImageAttr['mime'] . ' images are not supported';
             break;
     }
     if (isset($ermsg) || false === $oImage) {
         return false;
     }
     $oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]);
     if ($sourceImageAttr['mime'] == 'image/png') {
         $bg = imagecolorallocatealpha($oThumbImage, 255, 255, 255, 127);
         // (PHP 4 >= 4.3.2, PHP 5)
         imagefill($oThumbImage, 0, 0, $bg);
         imagealphablending($oThumbImage, false);
         imagesavealpha($oThumbImage, true);
     }
     //imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight);
     CKFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int) max(floor($quality / 20), 6));
     switch ($sourceImageAttr['mime']) {
         case 'image/gif':
             imagegif($oThumbImage, $targetFile);
             break;
         case 'image/jpeg':
         case 'image/bmp':
             imagejpeg($oThumbImage, $targetFile, $quality);
             break;
         case 'image/png':
             imagepng($oThumbImage, $targetFile);
             break;
         case 'image/wbmp':
             imagewbmp($oThumbImage, $targetFile);
             break;
     }
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     if (file_exists($targetFile) && ($perms = $_config->getChmodFiles())) {
         $oldUmask = umask(0);
         chmod($targetFile, $perms);
         umask($oldUmask);
     }
     imageDestroy($oImage);
     imageDestroy($oThumbImage);
     return true;
 }
Пример #11
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     // Create the "Files" node.
     $oFilesNode = new Ckfinder_Connector_Utils_XmlNode("Files");
     $this->_connectorNode->addChild($oFilesNode);
     if (!is_dir($_sServerDir)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     }
     $files = array();
     $thumbFiles = array();
     if ($dh = @opendir($_sServerDir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) {
                 $files[] = $file;
             }
         }
         closedir($dh);
     } else {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($files) > 0) {
         $_thumbnailsConfig = $_config->getThumbnailsConfig();
         $_thumbServerPath = '';
         $_showThumbs = !empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1;
         if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) {
             $_thumbServerPath = $this->_currentFolder->getThumbsServerPath();
         }
         natcasesort($files);
         $i = 0;
         foreach ($files as $file) {
             $filemtime = @filemtime($_sServerDir . $file);
             //otherwise file doesn't exist or we can't get it's filename properly
             if ($filemtime !== false) {
                 $filename = CKFinder_Connector_Utils_Misc::mbBasename($file);
                 if (!$resourceTypeInfo->checkExtension($filename, false)) {
                     continue;
                 }
                 if ($resourceTypeInfo->checkIsHiddenFile($filename)) {
                     continue;
                 }
                 $oFileNode[$i] = new Ckfinder_Connector_Utils_XmlNode("File");
                 $oFilesNode->addChild($oFileNode[$i]);
                 $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(CKFinder_Connector_Utils_Misc::mbBasename($file)));
                 $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime));
                 if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) {
                     if (file_exists($_thumbServerPath . $filename)) {
                         $oFileNode[$i]->addAttribute("thumb", $filename);
                     } elseif ($_showThumbs) {
                         $oFileNode[$i]->addAttribute("thumb", "?" . $filename);
                     }
                 }
                 $size = filesize($_sServerDir . $file);
                 if ($size && $size < 1024) {
                     $size = 1;
                 } else {
                     $size = (int) round($size / 1024);
                 }
                 $oFileNode[$i]->addAttribute("size", $size);
                 $i++;
             }
         }
     }
 }
Пример #12
0
 /**
  * send response (save uploaded file, resize if required)
  * @access public
  *
  */
 public function sendResponse()
 {
     $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE;
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $oRegistry->set("FileUpload_fileName", "unknown file");
     $uploadedFile = array_shift($_FILES);
     if (!isset($uploadedFile['name'])) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID);
     }
     $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name']));
     $sFileName = str_replace(array(":", "*", "?", "|", "/"), "_", $sUnsafeFileName);
     if ($_config->forceAscii()) {
         $sFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sFileName);
     }
     if ($sFileName != $sUnsafeFileName) {
         $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
     }
     //file named with chinese charactor
     $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
     $sFileName = date("Ymd") . "_" . date("His") . "." . $sExtension;
     //end
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $this->checkConnector();
     $this->checkRequest();
     if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (!$resourceTypeInfo->checkExtension($sFileName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
     }
     $sFileNameOrginal = $sFileName;
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
     $maxSize = $resourceTypeInfo->getMaxSize();
     if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
     }
     $htmlExtensions = $_config->getHtmlExtensions();
     $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     if ($htmlExtensions && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     }
     $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     $secureImageUploads = $_config->getSecureImageUploads();
     if ($secureImageUploads && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     }
     switch ($uploadedFile['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
             break;
         case UPLOAD_ERR_PARTIAL:
         case UPLOAD_ERR_NO_FILE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
         case UPLOAD_ERR_EXTENSION:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
     }
     $sServerDir = $this->_currentFolder->getServerPath();
     $iCounter = 0;
     //personnal
     $now = time();
     $yearDir = $sServerDir . '/' . date('Y', $now) . '/';
     if (!file_exists($yearDir) && !is_dir($yearDir)) {
         mkdir($yearDir, 0777);
     }
     $monthDir = $yearDir . date('m', $now) . '/';
     if (!file_exists($monthDir) && !is_dir($monthDir)) {
         mkdir($monthDir, 0777);
     }
     $dayDir = $monthDir . date('d', $now);
     if (!file_exists($dayDir) && !is_dir($dayDir)) {
         mkdir($dayDir, 0777);
     }
     $sServerDir = $dayDir;
     $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl() . date('Y', $now) . '/' . date('m', $now) . '/' . date('d', $now) . '/');
     //personnal end
     //file_put_contents($_SERVER['DOCUMENT_ROOT'].'/s.txt',$this->_currentFolder->getUrl());
     //
     while (true) {
         $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
         if (file_exists($sFilePath)) {
             $iCounter++;
             $sFileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . "(" . $iCounter . ")" . "." . CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
             $oRegistry->set("FileUpload_fileName", $sFileName);
             $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
         } else {
             if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
                 $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
             } else {
                 if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
                     @unlink($sFilePath);
                     $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
                 } else {
                     if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
                         @unlink($sFilePath);
                         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                     }
                 }
             }
             if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
                 $oldumask = umask(0);
                 @chmod($sFilePath, $perms);
                 umask($oldumask);
             }
             break;
         }
     }
     if (!$_config->checkSizeAfterScaling()) {
         $this->_errorHandler->throwError($iErrorNumber, true, false);
     }
     //resize image if required
     require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php";
     $_imagesConfig = $_config->getImagesConfig();
     if ($_imagesConfig->getMaxWidth() > 0 && $_imagesConfig->getMaxHeight() > 0 && $_imagesConfig->getQuality() > 0) {
         CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true);
     }
     if ($_config->checkSizeAfterScaling()) {
         //check file size after scaling, attempt to delete if too big
         clearstatcache();
         if ($maxSize && filesize($sFilePath) > $maxSize) {
             @unlink($sFilePath);
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
         } else {
             $this->_errorHandler->throwError($iErrorNumber, true, false);
         }
     }
     CKFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath));
 }
Пример #13
0
 function CKFinder_Connector_Core_ThumbnailsConfig($thumbnailsNode)
 {
     if (extension_loaded('gd') && isset($thumbnailsNode['enabled'])) {
         $this->_isEnabled = CKFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['enabled']);
     }
     if (isset($thumbnailsNode['directAccess'])) {
         $this->_directAccess = CKFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['directAccess']);
     }
     if (isset($thumbnailsNode['bmpSupported'])) {
         $this->_bmpSupported = CKFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['bmpSupported']);
     }
     if (isset($thumbnailsNode['maxWidth'])) {
         $_maxWidth = intval($thumbnailsNode['maxWidth']);
         if ($_maxWidth >= 0) {
             $this->_maxWidth = $_maxWidth;
         }
     }
     if (isset($thumbnailsNode['maxHeight'])) {
         $_maxHeight = intval($thumbnailsNode['maxHeight']);
         if ($_maxHeight >= 0) {
             $this->_maxHeight = $_maxHeight;
         }
     }
     if (isset($thumbnailsNode['quality'])) {
         $_quality = intval($thumbnailsNode['quality']);
         if ($_quality > 0 && $_quality <= 100) {
             $this->_quality = $_quality;
         }
     }
     if (isset($thumbnailsNode['url'])) {
         $this->_url = $thumbnailsNode['url'];
     }
     if (!strlen($this->_url)) {
         $this->_url = "/";
     } else {
         if (substr($this->_url, -1, 1) != "/") {
             $this->_url .= "/";
         }
     }
     if (isset($thumbnailsNode['directory'])) {
         $this->_directory = $thumbnailsNode['directory'];
     }
 }
Пример #14
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     // Create the "ConnectorInfo" node.
     $_oConnInfo = new Ckfinder_Connector_Utils_XmlNode("ConnectorInfo");
     $this->_connectorNode->addChild($_oConnInfo);
     $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false");
     if (!$_config->getIsEnabled()) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     }
     $_ln = '';
     $_lc = $_config->getLicenseKey() . '                                  ';
     $pos = strpos(CKFINDER_CHARS, $_lc[0]) % 5;
     if ($pos == 1 || $pos == 4) {
         $_ln = $_config->getLicenseName();
     }
     $_oConnInfo->addAttribute("s", $_ln);
     $_oConnInfo->addAttribute("c", trim($_lc[11] . $_lc[0] . $_lc[8] . $_lc[12] . $_lc[26] . $_lc[2] . $_lc[3] . $_lc[25] . $_lc[1]));
     $_thumbnailsConfig = $_config->getThumbnailsConfig();
     $_thumbnailsEnabled = $_thumbnailsConfig->getIsEnabled();
     $_oConnInfo->addAttribute("thumbsEnabled", $_thumbnailsEnabled ? "true" : "false");
     if ($_thumbnailsEnabled) {
         $_oConnInfo->addAttribute("thumbsUrl", $_thumbnailsConfig->getUrl());
         $_oConnInfo->addAttribute("thumbsDirectAccess", $_thumbnailsConfig->getDirectAccess() ? "true" : "false");
     }
     $_imagesConfig = $_config->getImagesConfig();
     $_oConnInfo->addAttribute("imgWidth", $_imagesConfig->getMaxWidth());
     $_oConnInfo->addAttribute("imgHeight", $_imagesConfig->getMaxHeight());
     // Create the "ResourceTypes" node.
     $_oResourceTypes = new Ckfinder_Connector_Utils_XmlNode("ResourceTypes");
     $this->_connectorNode->addChild($_oResourceTypes);
     // Create the "PluginsInfo" node.
     $_oPluginsInfo = new Ckfinder_Connector_Utils_XmlNode("PluginsInfo");
     $this->_connectorNode->addChild($_oPluginsInfo);
     // Load the resource types in an array.
     $_aTypes = $_config->getDefaultResourceTypes();
     if (!sizeof($_aTypes)) {
         $_aTypes = $_config->getResourceTypeNames();
     }
     $_aTypesSize = sizeof($_aTypes);
     if ($_aTypesSize) {
         $phpMaxSize = 0;
         $max_upload = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('upload_max_filesize'));
         if ($max_upload) {
             $phpMaxSize = $max_upload;
         }
         $max_post = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('post_max_size'));
         if ($max_post) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $max_post) : $max_post;
         }
         //ini_get('memory_limit') only works if compiled with "--enable-memory-limit"
         $memory_limit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'));
         if ($memory_limit && $memory_limit != -1) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memory_limit) : $memory_limit;
         }
         $_oConnInfo->addAttribute("uploadMaxSize", $phpMaxSize);
         $_oConnInfo->addAttribute("uploadCheckImages", $_config->checkSizeAfterScaling() ? "false" : "true");
         for ($i = 0; $i < $_aTypesSize; $i++) {
             $_resourceTypeName = $_aTypes[$i];
             $_acl = $_config->getAccessControlConfig();
             $_aclMask = $_acl->getComputedMask($_resourceTypeName, "/");
             if (($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) {
                 continue;
             }
             if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) {
                 //print $_resourceTypeName;
                 $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName);
                 //print_r($_oTypeInfo);
                 $_oResourceType[$i] = new Ckfinder_Connector_Utils_XmlNode("ResourceType");
                 $_oResourceTypes->addChild($_oResourceType[$i]);
                 $_oResourceType[$i]->addAttribute("name", $_resourceTypeName);
                 $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl());
                 $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions()));
                 $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions()));
                 $_oResourceType[$i]->addAttribute("hash", substr(md5($_oTypeInfo->getDirectory()), 0, 16));
                 $_oResourceType[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_oTypeInfo->getDirectory()) ? "true" : "false");
                 $_oResourceType[$i]->addAttribute("acl", $_aclMask);
                 $maxSize = $_oTypeInfo->getMaxSize();
                 if ($phpMaxSize) {
                     $maxSize = $maxSize ? min($maxSize, $phpMaxSize) : $phpMaxSize;
                 }
                 $_oResourceType[$i]->addAttribute("maxSize", $maxSize);
             }
         }
     }
     $config = $GLOBALS['config'];
     if (!empty($config['Plugins']) && is_array($config['Plugins'])) {
         $_oConnInfo->addAttribute("plugins", implode(",", $config['Plugins']));
     }
     CKFinder_Connector_Core_Hooks::run('InitCommand', array(&$this->_connectorNode));
 }
Пример #15
0
 /**
  * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php
  * function posted by e dot a dot schultz at gmail dot com
  *
  * @static
  * @access public
  * @param string $filename
  * @return boolean
  */
 public static function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels)
 {
     $MB = 1048576;
     // number of bytes in 1M
     $K64 = 65536;
     // number of bytes in 64K
     $TWEAKFACTOR = 2.4;
     // Or whatever works for you
     $memoryNeeded = round(($imageWidth * $imageHeight * $imageBits * $imageChannels / 8 + $K64) * $TWEAKFACTOR) + 3 * $MB;
     //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
     //Default memory limit is 8MB so well stick with that.
     //To find out what yours is, view your php.ini file.
     $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit')) / $MB;
     // There are no memory limits, nothing to do
     if ($memoryLimit == -1) {
         return true;
     }
     if (!$memoryLimit) {
         $memoryLimit = 8;
     }
     $memoryLimitMB = $memoryLimit * $MB;
     if (function_exists('memory_get_usage')) {
         if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) {
             $newLimit = $memoryLimit + ceil((memory_get_usage() + $memoryNeeded - $memoryLimitMB) / $MB);
             if (@ini_set('memory_limit', $newLimit . 'M') === false) {
                 return false;
             }
         }
     } else {
         if ($memoryNeeded + 3 * $MB > $memoryLimitMB) {
             $newLimit = $memoryLimit + ceil((3 * $MB + $memoryNeeded - $memoryLimitMB) / $MB);
             if (false === @ini_set('memory_limit', $newLimit . 'M')) {
                 return false;
             }
         }
     }
     return true;
 }
Пример #16
0
 /**
  * Get private zip plugin config
  *
  * @access protected
  * @return array
  */
 protected function getConfig()
 {
     $config = array();
     $config['zipMaxSize'] = 'default';
     if (isset($GLOBALS['config']['ZipMaxSize']) && (string) $GLOBALS['config']['ZipMaxSize'] != 'default') {
         $config['zipMaxSize'] = CKFinder_Connector_Utils_Misc::returnBytes((string) $GLOBALS['config']['ZipMaxSize']);
     }
     return $config;
 }
 /**
  * Get ResourceType configuration
  *
  * @param string $resourceTypeNode
  * @return array
  * 
  */
 function CKFinder_Connector_Core_ResourceTypeConfig($resourceTypeNode)
 {
     if (isset($resourceTypeNode["name"])) {
         $this->_name = $resourceTypeNode["name"];
     }
     if (isset($resourceTypeNode["url"])) {
         $this->_url = $resourceTypeNode["url"];
     }
     if (!strlen($this->_url)) {
         $this->_url = "/";
     } else {
         if (substr($this->_url, -1, 1) != "/") {
             $this->_url .= "/";
         }
     }
     if (isset($resourceTypeNode["maxSize"])) {
         $this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string) $resourceTypeNode["maxSize"]);
     }
     if (isset($resourceTypeNode["directory"])) {
         $this->_directory = $resourceTypeNode["directory"];
     }
     if (!strlen($this->_directory)) {
         $this->_directory = resolveUrl($this->_url);
     }
     if (isset($resourceTypeNode["allowedExtensions"])) {
         if (is_array($resourceTypeNode["allowedExtensions"])) {
             foreach ($resourceTypeNode["allowedExtensions"] as $extension) {
                 $this->_allowedExtensions[] = strtolower(trim((string) $e));
             }
         } else {
             $resourceTypeNode["allowedExtensions"] = trim((string) $resourceTypeNode["allowedExtensions"]);
             if (strlen($resourceTypeNode["allowedExtensions"])) {
                 $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
                 foreach ($extensions as $e) {
                     $this->_allowedExtensions[] = strtolower(trim($e));
                 }
             }
         }
     }
     if (isset($resourceTypeNode["deniedExtensions"])) {
         if (is_array($resourceTypeNode["deniedExtensions"])) {
             foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
                 $this->_deniedExtensions[] = strtolower(trim((string) $e));
             }
         } else {
             $resourceTypeNode["deniedExtensions"] = trim((string) $resourceTypeNode["deniedExtensions"]);
             if (strlen($resourceTypeNode["deniedExtensions"])) {
                 $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
                 foreach ($extensions as $e) {
                     $this->_deniedExtensions[] = strtolower(trim($e));
                 }
             }
         }
     }
     $_view = "";
     if (isset($resourceTypeNode["defaultView"])) {
         $_view = $resourceTypeNode["defaultView"];
     }
     if (!strlen($_view) && isset($GLOBALS['config']['DefaultDisplaySettings']['view'])) {
         $_view = $GLOBALS['config']['DefaultDisplaySettings']['view'];
     }
     if ($_view == "List") {
         $this->_defaultView = "List";
     }
 }
 /**
  * Checks whether the string is valid UTF8
  * @param string $string
  */
 public function asUTF8($string)
 {
     if (CKFinder_Connector_Utils_Misc::isValidUTF8($string)) {
         return $string;
     }
     $ret = "";
     for ($i = 0; $i < strlen($string); $i++) {
         $ret .= CKFinder_Connector_Utils_Misc::isValidUTF8($string[$i]) ? $string[$i] : "�";
     }
     return $ret;
 }
Пример #19
0
 /**
  * Create thumbnail
  *
  * @param string $sourceFile
  * @param string $targetFile
  * @param int $maxWidth
  * @param int $maxHeight
  * @param boolean $preserverAspectRatio
  * @return boolean
  * @static
  * @access public 
  */
 public static function createThumb($sourceFile, $targetFile, $maxWidth, $maxHeight, $quality, $preserverAspectRatio)
 {
     $sourceImageAttr = @getimagesize($sourceFile);
     if ($sourceImageAttr === false) {
         return false;
     }
     $sourceImageWidth = isset($sourceImageAttr[0]) ? $sourceImageAttr[0] : 0;
     $sourceImageHeight = isset($sourceImageAttr[1]) ? $sourceImageAttr[1] : 0;
     $sourceImageMime = isset($sourceImageAttr["mime"]) ? $sourceImageAttr["mime"] : "";
     $sourceImageBits = isset($sourceImageAttr["bits"]) ? $sourceImageAttr["bits"] : 8;
     $sourceImageChannels = isset($sourceImageAttr["channels"]) ? $sourceImageAttr["channels"] : 3;
     if (!$sourceImageWidth || !$sourceImageHeight || !$sourceImageMime) {
         return false;
     }
     $iFinalWidth = $maxWidth == 0 ? $sourceImageWidth : $maxWidth;
     $iFinalHeight = $maxHeight == 0 ? $sourceImageHeight : $maxHeight;
     if ($sourceImageWidth <= $iFinalWidth && $sourceImageHeight <= $iFinalHeight) {
         if ($sourceFile != $targetFile) {
             copy($sourceFile, $targetFile);
         }
         return true;
     }
     if ($preserverAspectRatio) {
         // Gets the best size for aspect ratio resampling
         $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight);
     } else {
         $oSize = array($iFinalWidth, $iFinalHeight);
     }
     CKFinder_Connector_Utils_Misc::setMemoryForImage($sourceImageWidth, $sourceImageHeight, $sourceImageBits, $sourceImageChannels);
     switch ($sourceImageAttr['mime']) {
         case 'image/gif':
             if (@imagetypes() & IMG_GIF) {
                 $oImage = @imagecreatefromgif($sourceFile);
             } else {
                 $ermsg = 'GIF images are not supported';
             }
             break;
         case 'image/jpeg':
             if (@imagetypes() & IMG_JPG) {
                 $oImage = @imagecreatefromjpeg($sourceFile);
             } else {
                 $ermsg = 'JPEG images are not supported';
             }
             break;
         case 'image/png':
             if (@imagetypes() & IMG_PNG) {
                 $oImage = @imagecreatefrompng($sourceFile);
             } else {
                 $ermsg = 'PNG images are not supported';
             }
             break;
         case 'image/wbmp':
             if (@imagetypes() & IMG_WBMP) {
                 $oImage = @imagecreatefromwbmp($sourceFile);
             } else {
                 $ermsg = 'WBMP images are not supported';
             }
             break;
         default:
             $ermsg = $sourceImageAttr['mime'] . ' images are not supported';
             break;
     }
     if (isset($ermsg) || false === $oImage) {
         return false;
     }
     $oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]);
     //imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight);
     CKFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int) max(floor($quality / 20), 1));
     switch ($sourceImageAttr['mime']) {
         case 'image/gif':
             imagegif($oThumbImage, $targetFile);
             break;
         case 'image/jpeg':
             imagejpeg($oThumbImage, $targetFile, $quality);
             break;
         case 'image/png':
             imagepng($oThumbImage, $targetFile);
             break;
         case 'image/wbmp':
             imagewbmp($oThumbImage, $targetFile);
             break;
     }
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     if (file_exists($targetFile) && ($perms = $_config->getChmodFiles())) {
         $oldUmask = umask(0);
         chmod($targetFile, $perms);
         umask($oldUmask);
     }
     imageDestroy($oImage);
     imageDestroy($oThumbImage);
     return true;
 }
Пример #20
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     // if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) {
     //     $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     // }
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     // Create the "Files" node.
     $oFilesNode = new Ckfinder_Connector_Utils_XmlNode("Files");
     $this->_connectorNode->addChild($oFilesNode);
     // if (!is_dir($_sServerDir)) {
     //     $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     // }
     $fileNames = array();
     $fileData = array();
     $thumbFiles = array();
     // if ($dh = @opendir($_sServerDir)) {
     //     while (($file = readdir($dh)) !== false) {
     //         if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) {
     //             $files[] = $file;
     //         }
     //     }
     //     closedir($dh);
     // } else {
     //     $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
     // }
     global $config;
     $s3 = s3_con();
     $items = $s3->getBucket($config['AmazonS3']['Bucket'], substr($_sServerDir, 1), null, null, '/', false);
     foreach ($items as $item) {
         //Make sure it's not empty (root folder usually) and not a sub-folder (evidenced from prefix key)
         if (array_key_exists('size', $item) && $item['size'] !== 0 && !array_key_exists('prefix', $item)) {
             $fileNames[] = $item['name'];
             $fileData[$item['name']] = $item;
         }
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($fileNames) > 0) {
         $_thumbnailsConfig = $_config->getThumbnailsConfig();
         $_thumbServerPath = '';
         $_showThumbs = !empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1;
         if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) {
             $_thumbServerPath = $this->_currentFolder->getThumbsServerPath();
         }
         natcasesort($fileNames);
         $i = 0;
         foreach ($fileNames as $file) {
             $filemtime = $fileData[$file]['time'];
             //otherwise file doesn't exist or we can't get it's filename properly
             if ($filemtime !== false) {
                 // $filename = CKFinder_Connector_Utils_Misc::mbBasename($file);
                 // if (!$resourceTypeInfo->checkExtension($filename, false)) {
                 //     continue;
                 // }
                 // if ($resourceTypeInfo->checkIsHiddenFile($filename)) {
                 //     continue;
                 // }
                 $oFileNode[$i] = new Ckfinder_Connector_Utils_XmlNode("File");
                 $oFilesNode->addChild($oFileNode[$i]);
                 $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(CKFinder_Connector_Utils_Misc::mbBasename($file)));
                 $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime));
                 if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) {
                     if (file_exists($_thumbServerPath . $filename)) {
                         $oFileNode[$i]->addAttribute("thumb", $filename);
                     } elseif ($_showThumbs) {
                         $oFileNode[$i]->addAttribute("thumb", "?" . $filename);
                     }
                 }
                 $size = $fileData[$file]['size'];
                 if ($size && $size < 1024) {
                     $size = 1;
                 } else {
                     $size = (int) round($size / 1024);
                 }
                 $oFileNode[$i]->addAttribute("size", $size);
                 $i++;
             }
         }
     }
 }
Пример #21
0
 /**
  * send response (save uploaded file, resize if required)
  * @access public
  *
  */
 public function sendResponse()
 {
     global $met_wate_class, $met_wate_bigimg, $met_text_wate, $met_text_bigsize, $met_text_color, $met_text_angle, $met_watermark, $met_text_fonts, $met_big_wate, $met_file_maxsize, $met_img_rename;
     $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE;
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $oRegistry->set("FileUpload_fileName", "unknown file");
     $uploadedFile = array_shift($_FILES);
     if (!isset($uploadedFile['name'])) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID);
     }
     $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name']));
     $sFileName = str_replace(array(":", "*", "?", "|", "/", "——", " "), "_", $sUnsafeFileName);
     if ($_config->getDisallowUnsafeCharacters()) {
         $sFileName = str_replace(";", "_", $sFileName);
     }
     if ($_config->forceAscii()) {
         $sFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sFileName);
     }
     $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
     $sFileName = str_replace(' ', '', $sFileName);
     if ($met_img_rename) {
         $sFileName = date("Ymd") . "_" . date("His") . "." . $sExtension;
     }
     if ($sFileName != $sUnsafeFileName) {
         $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
     }
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $this->checkConnector();
     $this->checkRequest();
     if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (!$resourceTypeInfo->checkExtension($sFileName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
     }
     $sFileNameOrginal = $sFileName;
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
     $maxSize = $resourceTypeInfo->getMaxSize();
     if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
     }
     if ($uploadedFile['size'] > $met_file_maxsize * 1024 * 1024) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG_MET);
     }
     $htmlExtensions = $_config->getHtmlExtensions();
     $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     if ($htmlExtensions && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     }
     $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     $secureImageUploads = $_config->getSecureImageUploads();
     if ($secureImageUploads && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     }
     switch ($uploadedFile['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
             break;
         case UPLOAD_ERR_PARTIAL:
         case UPLOAD_ERR_NO_FILE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
         case UPLOAD_ERR_EXTENSION:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
     }
     $sServerDir = $this->_currentFolder->getServerPath();
     $iCounter = 0;
     while (true) {
         $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
         if (file_exists($sFilePath)) {
             $iCounter++;
             $sFileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . "(" . $iCounter . ")" . "." . CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
             $oRegistry->set("FileUpload_fileName", $sFileName);
             $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
         } else {
             //move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)
             if (false === copy($uploadedFile['tmp_name'], $sFilePath)) {
                 $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
             } else {
                 if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
                     @unlink($sFilePath);
                     $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
                 } else {
                     if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
                         @unlink($sFilePath);
                         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                     }
                 }
             }
             if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
                 $oldumask = umask(0);
                 chmod($sFilePath, $perms);
                 umask($oldumask);
             }
             break;
         }
     }
     $sFileName_water = $sFileName;
     if (stristr(PHP_OS, "WIN")) {
         $sFileName_water = iconv("GBK", "utf-8", $sFileName);
     }
     if ($met_big_wate == 1) {
         require_once CKFINDER_CONNECTOR_CONFIG_watermark_PATHX;
         $img = new Watermark();
         if ($met_wate_class == 2) {
             $img->met_image_name = CKFINDER_CONNECTOR_CONFIG_img_PATHX . $met_wate_bigimg;
             $img->met_image_pos = $met_watermark;
         } else {
             $img->met_text = $met_text_wate;
             $img->met_text_size = $met_text_bigsize;
             $img->met_text_color = $met_text_color;
             $img->met_text_angle = $met_text_angle;
             $img->met_text_pos = $met_watermark;
             $img->met_text_font = CKFINDER_CONNECTOR_CONFIG_fonts_PATHX . $met_text_fonts;
         }
         if (!file_exists(CKFINDER_CONNECTOR_CONFIG_upload_PATHX . "/images/watermark/")) {
             mkdir(CKFINDER_CONNECTOR_CONFIG_upload_PATHX . "/images/watermark/");
         }
         $img->src_image_name = CKFINDER_CONNECTOR_CONFIG_upload_PATHX . "/images/{$sFileName_water}";
         $img->save_file = CKFINDER_CONNECTOR_CONFIG_upload_PATHX . "/images/watermark/{$sFileName_water}";
         $img->create();
     }
     if (!$_config->checkSizeAfterScaling()) {
         $this->_errorHandler->throwError($iErrorNumber, true, false);
     }
     //resize image if required
     require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php";
     $_imagesConfig = $_config->getImagesConfig();
     /*图片如果超过设定最大值,则把图片缩小
             if ($_imagesConfig->getMaxWidth()>0 && $_imagesConfig->getMaxHeight()>0 && $_imagesConfig->getQuality()>0) {
                 CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true) ;
             }
     		*/
     if ($met_big_wate == 1) {
         $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl() . 'watermark/');
     }
     if ($_config->checkSizeAfterScaling()) {
         //check file size after scaling, attempt to delete if too big
         clearstatcache();
         if ($maxSize && filesize($sFilePath) > $maxSize) {
             @unlink($sFilePath);
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
         } else {
             $this->_errorHandler->throwError($iErrorNumber, true, false);
         }
     }
     CKFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath));
 }