$error = $_FILES['myfile']['error']; $result = 1; } } } else { $event_id = $_REQUEST['event_id']; if ($doc_id) { if ($document_name != '') { $target_path = $destination_path . basename($document_name_pre); move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path); } $evt->addDocuments('server', $event_id, $doc_id, '', $document_status, ''); $error = $_FILES['myfile']['error']; $result = 2; } else { $doc_name = getRandomName($document_name); if ($document_name != '' && $document_status != '') { $target_path = $destination_path . basename($doc_name); move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path); $evt->addDocuments('server', $event_id, '', $document_name, $document_status, $doc_name); $error = $_FILES['myfile']['error']; $result = 1; } } } } } else { if ($document_name != '' && $document_size == 0) { $result = 3; } }
/** * 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); } //修改其上传后的文件名字 $sFileName = getRandomName() . '.' . CKFinder_Connector_Utils_FileSystem::getExtension($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($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); } } } 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)); }
function publish($siteid, $version, $description, $filename, $md5, $type) { global $cfg, $data, $versions, $ext; $rt = array('result' => false, 'error' => -1); $debug = '1'; $list = getList(false); $site = $list[$siteid]; //$debug= json_encode($site); //$debug = $description; //file_put_contents("debug.log", strtolower(md5_file($filename))) //file_put_contents("debug.log", strtolower(md5_file($filename))) if ($site != null && file_exists($filename) && strtolower(md5_file($filename)) == strtolower(trim($md5))) { if ($site['current_version'] == $version) { //10 publish 发布版本和线上版本一致 $rt['error'] = 10; return $rt; } //检查目标路径 $p = $site['root'] . $version; $tmp = $cfg['tmp_unzip'] . getRandomName($siteid . '_' . $version . '_tmp/'); if (file_exists($p)) { //如果存在则备份配置 //删除已经存在的文件目录 if ($site['backup']) { backup($p, $site['backup'] . getRandomName($siteid . '_' . $version . '.zip')); } $r = delDirAndFile($p); if ($r == 0) { $debug = $p; //9 publish 目录创建失败 $rt['error'] = 9; } } if ($site['upload']) { //备份上传文件 copy($filename, $site['upload'] . str_replace($cfg['tmp_upload'], '', $filename)); } if ($rt['error'] == -1) { if (!mkdir($p) || !mkdir($tmp)) { //9 publish 目录创建失败 $debug = $p . ' ' . $tmp; $rt['error'] = 9; } else { if ($type && strtolower($type) == 'copyreplace') { //拷贝当前版本 FileUtil::copyDir($site['root'] . $site['current_version'], $p, true); } //解压缩文件到临时目录 $z = new ZipArchive(); //die(file_exists($filename)); $z->open($filename); $z->extractTo($tmp); //将临时目录下的deploy目录拷贝到目标路径 if (file_exists($tmp . 'deploy')) { //将部署程序从deploy目录下拷贝到目标路径 FileUtil::copyDir($tmp . 'deploy', $p, true); if ($versions[$siteid] == null) { $versions[$siteid] = array(); } $intver = intval($version); $versions[$siteid][$intver] = array('version' => $intver, 'description' => $description, 'date' => date("Y-m-d H:i:s", time())); save_records($data, $ext, $versions); $rt['error'] = 0; $rt['result'] = true; } else { $rt['error'] = 7; $debug = '上传文件无deploy目录'; } //删除临时目录 /* FileUtil::unlinkFile($filename); FileUtil::unlinkDir($tmp); */ } } } else { //8 publish upload md5 校验失败 $rt['error'] = 8; } $rt['msg'] = $debug; return $rt; }