当前位置: 首页>>代码示例>>PHP>>正文


PHP CFile::saveFile方法代码示例

本文整理汇总了PHP中CFile::saveFile方法的典型用法代码示例。如果您正苦于以下问题:PHP CFile::saveFile方法的具体用法?PHP CFile::saveFile怎么用?PHP CFile::saveFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFile的用法示例。


在下文中一共展示了CFile::saveFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: extractValue

 /**
  * @param FieldType $fieldType
  * @param array $field
  * @param array $request
  * @return null|int
  */
 protected static function extractValue(FieldType $fieldType, array $field, array $request)
 {
     $value = parent::extractValue($fieldType, $field, $request);
     if (is_array($value) && !empty($value['name']) && !empty($value['tmp_name'])) {
         if (!is_uploaded_file($value['tmp_name'])) {
             $value = null;
             static::addError(array('code' => 'ErrorValue', 'message' => Loc::getMessage('BPDT_FILE_SECURITY_ERROR'), 'parameter' => static::generateControlName($field)));
         } else {
             if (!array_key_exists('MODULE_ID', $value) || strlen($value['MODULE_ID']) <= 0) {
                 $value['MODULE_ID'] = 'bizproc';
             }
             $value = \CFile::saveFile($value, 'bizproc_wf', true, true);
             if (!$value) {
                 $value = null;
                 static::addError(array('code' => 'ErrorValue', 'message' => Loc::getMessage('BPDT_FILE_INVALID'), 'parameter' => static::generateControlName($field)));
             }
         }
     } else {
         $value = null;
     }
     return $value;
 }
开发者ID:k-kalashnikov,项目名称:geekcon,代码行数:28,代码来源:file.php

示例2: GetFieldInputValue


//.........这里部分代码省略.........
                             }
                         } else {
                             if (!array_key_exists($value, $fieldType["Options"])) {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"), "parameter" => $fieldName["Field"]);
                             }
                         }
                     }
                 } elseif ($fieldType["Type"] == "bool") {
                     if ($value !== "Y" && $value !== "N") {
                         if ($value === true) {
                             $value = "Y";
                         } elseif ($value === false) {
                             $value = "N";
                         } elseif (strlen($value) > 0) {
                             $value = strtolower($value);
                             if (in_array($value, array("y", "yes", "true", "1"))) {
                                 $value = "Y";
                             } elseif (in_array($value, array("n", "no", "false", "0"))) {
                                 $value = "N";
                             } else {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("BPCGWTL_INVALID45"), "parameter" => $fieldName["Field"]);
                             }
                         } else {
                             $value = null;
                         }
                     }
                 } elseif ($fieldType["Type"] == "file") {
                     if (is_array($value) && array_key_exists("name", $value) && strlen($value["name"]) > 0) {
                         if (!array_key_exists("MODULE_ID", $value) || strlen($value["MODULE_ID"]) <= 0) {
                             $value["MODULE_ID"] = "bizproc";
                         }
                         $value = CFile::saveFile($value, "bizproc_wf", true, true);
                         if (!$value) {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("BPCGWTL_INVALID915"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "date") {
                     if (strlen($value) > 0) {
                         if (!CheckDateTime($value, FORMAT_DATE)) {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_DATE"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "datetime") {
                     if (strlen($value) > 0) {
                         $valueTemporary = array();
                         $valueTemporary["VALUE"] = $value;
                         $result = CIBlockPropertyDateTime::checkFields('', $valueTemporary);
                         if (!empty($result)) {
                             $message = '';
                             foreach ($result as $error) {
                                 $message .= $error;
                             }
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => $message, "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
开发者ID:Satariall,项目名称:izurit,代码行数:67,代码来源:bizprocdocument.php

示例3: processActionCommit

 protected function processActionCommit()
 {
     $this->checkRequiredPostParams(array('editSessionId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $this->checkUpdatePermissions();
     $currentSession = $this->getEditSessionByCurrentUser((int) $this->request->getPost('editSessionId'));
     if (!$currentSession) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_EDIT_SESSION'), self::ERROR_COULD_NOT_FIND_EDIT_SESSION)));
         $this->sendJsonErrorResponse();
     }
     $tmpFile = \CTempFile::getFileName(uniqid('_wd'));
     checkDirPath($tmpFile);
     $fileData = new FileData();
     $fileData->setId($currentSession->getServiceFileId());
     $fileData->setSrc($tmpFile);
     $newNameFileAfterConvert = null;
     if ($this->documentHandler->isNeedConvertExtension($this->file->getExtension())) {
         $newNameFileAfterConvert = getFileNameWithoutExtension($this->file->getName()) . '.' . $this->documentHandler->getConvertExtension($this->file->getExtension());
         $fileData->setMimeType(TypeFile::getMimeTypeByFilename($newNameFileAfterConvert));
     } else {
         $fileData->setMimeType(TypeFile::getMimeTypeByFilename($this->file->getName()));
     }
     $fileData = $this->documentHandler->downloadFile($fileData);
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->deleteEditSession($currentSession);
     $oldName = $this->file->getName();
     //rename in cloud service
     $renameInCloud = $fileData->getName() && $fileData->getName() != $this->file->getName();
     if ($newNameFileAfterConvert || $renameInCloud) {
         if ($newNameFileAfterConvert && $renameInCloud) {
             $newNameFileAfterConvert = getFileNameWithoutExtension($fileData->getName()) . '.' . getFileExtension($newNameFileAfterConvert);
         }
         $this->file->rename($newNameFileAfterConvert);
     }
     $fileArray = \CFile::makeFileArray($tmpFile);
     $fileArray['name'] = $this->file->getName();
     $fileArray['type'] = $fileData->getMimeType();
     $fileArray['MODULE_ID'] = Driver::INTERNAL_MODULE_ID;
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileId = \CFile::saveFile($fileArray, Driver::INTERNAL_MODULE_ID);
     if (!$fileId) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_SAVE_FILE'), self::ERROR_COULD_NOT_SAVE_FILE)));
         $this->sendJsonErrorResponse();
     }
     $versionModel = $this->file->addVersion(array('ID' => $fileId, 'FILE_SIZE' => $fileArray['size']), $this->getUser()->getId(), true);
     if (!$versionModel) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_ADD_VERSION'), self::ERROR_COULD_NOT_ADD_VERSION)));
         $this->errorCollection->add($this->file->getErrors());
         $this->sendJsonErrorResponse();
     }
     if ($this->isLastEditSessionForFile()) {
         $this->deleteFile($currentSession, $fileData);
     }
     $this->sendJsonSuccessResponse(array('objectId' => $this->file->getId(), 'newName' => $this->file->getName(), 'oldName' => $oldName));
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:65,代码来源:documentcontroller.php

示例4: UploadAvatar

 public static function UploadAvatar($hash, &$file, &$package, &$upload, &$error)
 {
     $post = \Bitrix\Main\Context::getCurrent()->getRequest()->getPostList()->toArray();
     $chatId = intval($post['CHAT_ID']);
     if ($chatId <= 0) {
         return false;
     }
     $chat = IM\ChatTable::getById($chatId)->fetch();
     if (!$chat) {
         return false;
     }
     $relationError = true;
     $chatRelation = CIMChat::GetRelationById($chatId);
     foreach ($chatRelation as $relation) {
         if ($relation['USER_ID'] == self::GetUserId()) {
             $relationError = false;
             break;
         }
     }
     if ($relationError) {
         $error = GetMessage('IM_DISK_ERR_AVATAR_1');
         return false;
     }
     $fileId = CFile::saveFile($file["files"]["default"], self::MODULE_ID);
     if ($fileId > 0) {
         if ($chat['AVATAR'] > 0) {
             CFile::DeLete($chat['AVATAR']);
         }
         IM\ChatTable::update($chatId, array('AVATAR' => $fileId));
         $file['chatId'] = $chatId;
         $file['chatAvatar'] = CIMChat::GetAvatarImage($fileId);
         if ($chat["ENTITY_TYPE"] != 'CALL') {
             CIMChat::AddSystemMessage(array('CHAT_ID' => $chatId, 'USER_ID' => self::GetUserId(), 'MESSAGE_CODE' => 'IM_DISK_AVATAR_CHANGE_'));
         }
         if (CModule::IncludeModule('pull')) {
             $pullMessage = array('module_id' => 'im', 'command' => 'chatAvatar', 'params' => array('chatId' => $chatId, 'chatAvatar' => $file['chatAvatar']));
             CPullStack::AddByUsers(array_keys($chatRelation), $pullMessage);
             $orm = \Bitrix\Im\ChatTable::getById($chatId);
             $chat = $orm->fetch();
             if ($chat['TYPE'] == IM_MESSAGE_OPEN) {
                 CPullWatch::AddToStack('IM_PUBLIC_' . $chat['ID'], $pullMessage);
             }
         }
     } else {
         return false;
     }
     return true;
 }
开发者ID:webgksupport,项目名称:alpina,代码行数:48,代码来源:im_disk.php

示例5: updateFile

 /**
  * @param         $name
  * @param         $targetElementId
  * @param TmpFile $tmpFile
  * @param array   $data
  * @return array|bool
  * @throws AccessDeniedException
  */
 public function updateFile($name, $targetElementId, TmpFile $tmpFile, array $data = array())
 {
     /** @var File $file */
     $file = File::loadById($targetElementId);
     if (!$file) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetElementId}", 11154)));
         $tmpFile->delete();
         return false;
     }
     if (!$file->canUpdate($this->storage->getCurrentUserSecurityContext())) {
         $tmpFile->delete();
         throw new AccessDeniedException();
     }
     /** @var array $fileArray */
     if ($tmpFile->isCloud() && $tmpFile->getContentType()) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $fileId = \CFile::saveFile(array('name' => $tmpFile->getFilename(), 'tmp_name' => $tmpFile->getAbsolutePath(), 'type' => $tmpFile->getContentType()), Driver::INTERNAL_MODULE_ID, true, true);
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $fileArray = \CFile::getFileArray($fileId);
         if (!$fileArray) {
             $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " getFileArray", 1115541)));
             $tmpFile->delete();
             return false;
         }
         if (!empty($data['originalTimestamp'])) {
             $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
         }
         if ($file->addVersion($fileArray, $this->getUser()->getId())) {
             $tmpFile->delete();
             $this->loadFormattedFolderTreeAndBreadcrumbs();
             return $this->formatFileToResponse($file);
         } else {
             \CFile::delete($fileId);
         }
     } else {
         $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath());
         if (!$fileArray) {
             $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155)));
             $tmpFile->delete();
             return false;
         }
         if (!empty($data['originalTimestamp'])) {
             $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
         }
         if ($file->uploadVersion($fileArray, $this->getUser()->getId())) {
             $tmpFile->delete();
             $this->loadFormattedFolderTreeAndBreadcrumbs();
             return $this->formatFileToResponse($file);
         }
     }
     $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156)));
     $this->errorCollection->add($file->getErrors());
     $tmpFile->delete();
     return false;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:63,代码来源:diskstorage.php

示例6: AddAttachment

 function AddAttachment($arFields)
 {
     global $DB;
     $strSql = "SELECT ATTACHMENTS FROM b_mail_message WHERE ID=" . IntVal($arFields["MESSAGE_ID"]);
     $dbr = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!($dbr_arr = $dbr->Fetch())) {
         return false;
     }
     $n = IntVal($dbr_arr["ATTACHMENTS"]) + 1;
     if (strlen($arFields["FILE_NAME"]) <= 0) {
         $arFields["FILE_NAME"] = $n . ".";
         if (strpos($arFields["CONTENT_TYPE"], "message/") === 0) {
             $arFields["FILE_NAME"] .= "msg";
         } else {
             $arFields["FILE_NAME"] .= "tmp";
         }
     }
     if (is_set($arFields, "CONTENT_TYPE")) {
         $arFields["CONTENT_TYPE"] = strtolower($arFields["CONTENT_TYPE"]);
     }
     if (strpos($arFields["CONTENT_TYPE"], "image/") === 0 && (!is_set($arFields, "IMAGE_WIDTH") || !is_set($arFields, "IMAGE_HEIGHT")) && is_set($arFields, "FILE_DATA")) {
         $filename = CTempFile::GetFileName(md5(uniqid("")) . '.tmp');
         CheckDirPath($filename);
         if (file_put_contents($filename, $arFields["FILE_DATA"]) !== false) {
             $img_arr = CFile::GetImageSize($filename);
             $arFields["IMAGE_WIDTH"] = $img_arr ? $img_arr[0] : 0;
             $arFields["IMAGE_HEIGHT"] = $img_arr ? $img_arr[1] : 0;
         }
     }
     if (is_set($arFields, "FILE_DATA") && !is_set($arFields, "FILE_SIZE")) {
         $arFields["FILE_SIZE"] = CUtil::BinStrlen($arFields["FILE_DATA"]);
     }
     $file = array('name' => md5($arFields['FILE_NAME']), 'size' => $arFields['FILE_SIZE'], 'type' => $arFields['CONTENT_TYPE'], 'content' => $arFields['FILE_DATA'], 'MODULE_ID' => 'mail');
     if (!($file_id = CFile::saveFile($file, 'mail/attachment'))) {
         return false;
     }
     unset($arFields['FILE_DATA']);
     $arFields['FILE_ID'] = $file_id;
     $ID = $DB->add('b_mail_msg_attachment', $arFields);
     if ($ID > 0) {
         $strSql = 'UPDATE b_mail_message SET ATTACHMENTS = ' . $n . ' WHERE ID = ' . intval($arFields['MESSAGE_ID']);
         $DB->query($strSql, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__);
     }
     return $ID;
 }
开发者ID:Satariall,项目名称:izurit,代码行数:45,代码来源:mail.php


注:本文中的CFile::saveFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。