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


PHP CTempFile::GetFileName方法代码示例

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


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

示例1: getFileInfo

 /**
  * @return string
  */
 public function getFileInfo()
 {
     $fileInfo = null;
     if ($this->encoding === 'B' || $this->encoding === 'BASE64') {
         $type = $this->type !== '' ? strtolower($this->type) : 'jpg';
         if ($type === '' || !in_array($type, explode(',', \CFile::GetImageExtensions()), true)) {
             $type = 'jpg';
         }
         $filePath = \CTempFile::GetFileName(uniqid('vcard_img') . '.' . $type);
         CheckDirPath($filePath);
         //Removing of line folding
         $encodedData = preg_replace("/\\\\n/i", "\n", $this->value);
         if (file_put_contents($filePath, base64_decode($encodedData)) !== false) {
             $fileInfo = \CFile::MakeFileArray($filePath, "image/{$type}");
         }
     } elseif ($this->valueType === 'URI' && \CCrmUrlUtil::HasScheme($this->value) && \CCrmUrlUtil::IsSecureUrl($this->value)) {
         $fileInfo = \CFile::MakeFileArray($this->value);
     }
     return is_array($fileInfo) && strlen(\CFile::CheckImageFile($fileInfo)) === 0 ? $fileInfo : null;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:23,代码来源:vcardfile.php

示例2: processActionCommit

 protected function processActionCommit()
 {
     if (!$this->checkPermission()) {
         $this->sendJsonResponse(array('status' => self::STATUS_DENIED));
     }
     if (!isset($_FILES['file'])) {
         $this->sendJsonResponse(array('status' => self::STATUS_DENIED, 'message' => 'Upload file'));
     }
     $downloadedFile = $_FILES['file'];
     $webdav = $this->getWebdav();
     if (empty($webdav->arParams['element_array']['ID'])) {
         $this->sendJsonResponse(array('status' => self::STATUS_NOT_FOUND));
     }
     $filename = CTempFile::GetFileName(uniqid('_wd'));
     $nameToSavedFile = $webdav->arParams['element_name'];
     CheckDirPath($filename);
     if (($downloadedFile['error'] = intval($downloadedFile['error'])) > 0) {
         if ($downloadedFile['error'] < 3) {
             $this->sendJsonResponse(array('status' => self::STATUS_ERROR, 'message' => "Upload error: {$downloadedFile['error']}"));
         } else {
             $this->sendJsonResponse(array('status' => self::STATUS_ERROR, 'message' => "Upload error: {$downloadedFile['error']}"));
         }
     }
     if (!is_uploaded_file($downloadedFile['tmp_name'])) {
         $this->sendJsonResponse(array('status' => self::STATUS_ERROR, 'message' => "Upload error"));
     }
     if (!move_uploaded_file($downloadedFile['tmp_name'], $filename)) {
         $this->sendJsonResponse(array('status' => self::STATUS_ERROR, 'message' => "Bad move after upload"));
     }
     $options = array('new' => false, 'FILE_NAME' => $nameToSavedFile, 'ELEMENT_ID' => $webdav->arParams['element_array']['ID'], 'arUserGroups' => $webdav->USER['GROUPS'], 'TMP_FILE' => $filename);
     $this->getDb()->startTransaction();
     if (!$this->getWebDav()->put_commit($options)) {
         $this->getDb()->rollback();
         $this->sendJsonResponse(array('status' => self::STATUS_ERROR, 'message' => 'Error in commit.', 'description' => $webdav->LAST_ERROR));
     }
     $this->getDb()->commit();
     $this->sendJsonResponse(array('status' => self::STATUS_SUCCESS));
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:38,代码来源:class.php

示例3: ResizePicture

	public static function ResizePicture($arFile, $arResize)
	{
		if(strlen($arFile["tmp_name"]) <= 0)
			return $arFile;

		if(array_key_exists("error", $arFile) && $arFile["error"] !== 0)
			return GetMessage("IBLOCK_BAD_FILE_ERROR");

		$file = $arFile["tmp_name"];

		if(!file_exists($file) && !is_file($file))
			return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");

		$width = intval($arResize["WIDTH"]);
		$height = intval($arResize["HEIGHT"]);

		if($width <= 0 && $height <= 0)
			return $arFile;

		$orig = CFile::GetImageSize($file, true);
		if(!is_array($orig))
			return GetMessage("IBLOCK_BAD_FILE_NOT_PICTURE");

		$width_orig = $orig[0];
		$height_orig = $orig[1];

		$orientation = 0;
		$exifData = array();
		$image_type = $orig[2];
		if($image_type == IMAGETYPE_JPEG)
		{
			$exifData = CFile::ExtractImageExif($file);
			if ($exifData  && isset($exifData['Orientation']))
			{
				$orientation = $exifData['Orientation'];
				if ($orientation >= 5 && $orientation <= 8)
				{
					$width_orig = $orig[1];
					$height_orig = $orig[0];
				}
			}
		}

		if(($width > 0 && $orig[0] > $width) || ($height > 0 && $orig[1] > $height))
		{
			if($arFile["COPY_FILE"] == "Y")
			{
				$new_file = CTempFile::GetFileName(basename($file));
				CheckDirPath($new_file);
				$arFile["copy"] = true;

				if(copy($file, $new_file))
					$file = $new_file;
				else
					return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");
			}

			if($width <= 0)
				$width = $width_orig;

			if($height <= 0)
				$height = $height_orig;

			$height_new = $height_orig;
			if($width_orig > $width)
				$height_new = $width * $height_orig  / $width_orig;

			if($height_new > $height)
				$width = $height * $width_orig / $height_orig;
			else
				$height = $height_new;

			$image_type = $orig[2];
			if($image_type == IMAGETYPE_JPEG)
			{
				$image = imagecreatefromjpeg($file);
				if ($image === false)
				{
					ini_set('gd.jpeg_ignore_warning', 1);
					$image = imagecreatefromjpeg($file);
				}

				if ($orientation > 1)
				{
					if ($orientation == 7 || $orientation == 8)
						$image = imagerotate($image, 90, null);
					elseif ($orientation == 3 || $orientation == 4)
						$image = imagerotate($image, 180, null);
					elseif ($orientation == 5 || $orientation == 6)
						$image = imagerotate($image, 270, null);

					if (
						$orientation == 2 || $orientation == 7
						|| $orientation == 4 || $orientation == 5
					)
					{
						CFile::ImageFlipHorizontal($image);
					}
				}
			}
//.........这里部分代码省略.........
开发者ID:ASDAFF,项目名称:1C_Bitrix_info_site,代码行数:101,代码来源:iblock.php

示例4: array

         $arFilter["ID!"] = $ID;
     }
     $db_res = CIBlockSection::GetList(array(), $arFilter);
     if ($db_res && ($res = $db_res->Fetch())) {
         $arError = array("code" => "CODE_EXIST", "title" => GetMessage("P_ERROR_CODE_EXIST"));
     }
 }
 $arFiles = array();
 if (empty($arError) && !empty($_FILES["AVATAR"]) && !empty($_FILES["AVATAR"]["tmp_name"])) {
     include_once $_SERVER["DOCUMENT_ROOT"] . "/" . BX_PERSONAL_ROOT . "/components/bitrix/photogallery.upload/functions.php";
     $arRealFile = $_FILES["AVATAR"];
     $arAlbumSights = array("DETAIL_PICTURE" => array("code" => "album", "notes" => "for_album", "width" => $arParams["GALLERY_AVATAR"]["WIDTH"], "height" => $arParams["GALLERY_AVATAR"]["HEIGHT"]), "PICTURE" => array("code" => "album_thumbs", "notes" => "for_album", "width" => $arParams["GALLERY_AVATAR_THUMBS"]["WIDTH"], "height" => $arParams["GALLERY_AVATAR_THUMBS"]["HEIGHT"]));
     foreach ($arAlbumSights as $key => $Sight) {
         $File = $arRealFile;
         $File["name"] = "avatar_" . $Sight["code"] . $arRealFile["name"];
         $File["tmp_name"] = $File["tmp_name"] = CTempFile::GetFileName() . $File["name"];
         CFile::ResizeImageFile($arRealFile["tmp_name"], $File['tmp_name'], $Sight, BX_RESIZE_IMAGE_EXACT);
         $File["MODULE_ID"] = "iblock";
         $arFiles[$key] = $File;
     }
 }
 if (empty($arError)) {
     $arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", 0, LANGUAGE_ID);
     if (empty($arUserFields) || empty($arUserFields["UF_DEFAULT"])) {
         $db_res = CUserTypeEntity::GetList(array($by => $order), array("ENTITY_ID" => "IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", "FIELD_NAME" => "UF_DEFAULT"));
         if (!$db_res || !($res = $db_res->GetNext())) {
             $arFields = array("ENTITY_ID" => "IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", "FIELD_NAME" => "UF_DEFAULT", "USER_TYPE_ID" => "string", "MULTIPLE" => "N", "MANDATORY" => "N");
             $arFieldName = array();
             $rsLanguage = CLanguage::GetList($by, $order, array());
             while ($arLanguage = $rsLanguage->Fetch()) {
                 if (LANGUAGE_ID == $arLanguage["LID"]) {
开发者ID:Satariall,项目名称:izurit,代码行数:31,代码来源:component.php

示例5: saveNewFile

 protected function saveNewFile(array $fileData)
 {
     $filename = CTempFile::GetFileName(uniqid('_wd'));
     CheckDirPath($filename);
     $doc = $this->getDocHandler()->downloadFile(array('id' => $this->getFileId(), 'mimeType' => $this->getWebdav()->get_mime_type('1.' . $fileData['createType'])));
     file_put_contents($filename, $doc['content']);
     global $USER;
     $dataUserSection = CWebDavIblock::getRootSectionDataForUser($USER->GetID());
     if (!$dataUserSection) {
         return array('status' => 'error');
     }
     $createdDocFolderId = CIBlockWebdavSocnet::createCreatedDocFolder($dataUserSection['IBLOCK_ID'], $dataUserSection['SECTION_ID'], $USER->GetID());
     if (!$createdDocFolderId) {
         return array('status' => 'error');
     }
     $storage = new CWebDavStorageCore();
     $storage->setStorageId(array('IBLOCK_ID' => $dataUserSection['IBLOCK_ID'], 'IBLOCK_SECTION_ID' => $dataUserSection['SECTION_ID']));
     $nameToSavedFile = $storage->regenerateNameIfNonUnique($doc['name'], $createdDocFolderId);
     $tmpFile = new CWebDavStubTmpFile();
     $tmpFile->path = $filename;
     try {
         $fileData = $storage->addFile($nameToSavedFile, $createdDocFolderId, $tmpFile);
         $response = array('status' => 'success', 'elementId' => $fileData['extra']['id'], 'sectionId' => $fileData['extra']['sectionId'], 'name' => $nameToSavedFile, 'sizeInt' => $fileData['size'], 'type' => CWebDavBase::get_mime_type($nameToSavedFile), 'link' => str_replace('#element_id#', $fileData['extra']['id'], CWebDavSocNetEvent::getRuntime()->arPath['ELEMENT_EDIT_INLINE_URL']), 'nameWithoutExtension' => GetFileNameWithoutExtension($nameToSavedFile));
     } catch (Exception $e) {
         $response = array('status' => 'error');
     }
     return $response;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:28,代码来源:editdoccomponentbase.php

示例6: ResizeImageFile

 function ResizeImageFile($sourceFile, &$destinationFile, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, $arWaterMark = array(), $jpgQuality = false, $arFilters = false)
 {
     $io = CBXVirtualIo::GetInstance();
     if (!$io->FileExists($sourceFile)) {
         return false;
     }
     $bNeedCreatePicture = false;
     if ($resizeType != BX_RESIZE_IMAGE_EXACT && $resizeType != BX_RESIZE_IMAGE_PROPORTIONAL_ALT) {
         $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL;
     }
     if (!is_array($arSize)) {
         $arSize = array();
     }
     if (!array_key_exists("width", $arSize) || intval($arSize["width"]) <= 0) {
         $arSize["width"] = 0;
     }
     if (!array_key_exists("height", $arSize) || intval($arSize["height"]) <= 0) {
         $arSize["height"] = 0;
     }
     $arSize["width"] = intval($arSize["width"]);
     $arSize["height"] = intval($arSize["height"]);
     $arSourceSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
     $arDestinationSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
     $arSourceFileSizeTmp = CFile::GetImageSize($sourceFile);
     if (!in_array($arSourceFileSizeTmp[2], array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_BMP))) {
         return false;
     }
     if (class_exists("imagick") && function_exists('memory_get_usage')) {
         //When memory limit reached we'll try to use ImageMagic
         $memoryNeeded = round(($arSourceFileSizeTmp[0] * $arSourceFileSizeTmp[1] * $arSourceFileSizeTmp['bits'] * ($arSourceFileSizeTmp['channels'] > 0 ? $arSourceFileSizeTmp['channels'] : 1) / 8 + pow(2, 16)) * 1.65);
         $memoryLimit = CUtil::Unformat(ini_get('memory_limit'));
         if (memory_get_usage() + $memoryNeeded > $memoryLimit) {
             if ($arSize["width"] <= 0 || $arSize["height"] <= 0) {
                 $arSize["width"] = $arSourceFileSizeTmp[0];
                 $arSize["height"] = $arSourceFileSizeTmp[1];
             }
             CFile::ScaleImage($arSourceFileSizeTmp[0], $arSourceFileSizeTmp[1], $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
             if ($bNeedCreatePicture) {
                 $new_image = CTempFile::GetFileName(bx_basename($sourceFile));
                 CheckDirPath($new_image);
                 $im = new Imagick();
                 try {
                     $im->setSize($arDestinationSize["width"], $arDestinationSize["height"]);
                     $im->readImage($io->GetPhysicalName($sourceFile));
                     $im->setImageFileName($new_image);
                     $im->thumbnailImage($arDestinationSize["width"], $arDestinationSize["height"], true);
                     $im->writeImage();
                     $im->destroy();
                 } catch (ImagickException $e) {
                     $new_image = "";
                 }
                 if ($new_image != "") {
                     $sourceFile = $new_image;
                     $arSourceFileSizeTmp = CFile::GetImageSize($io->GetPhysicalName($sourceFile));
                 }
             }
         }
     }
     if ($io->Copy($sourceFile, $destinationFile)) {
         switch ($arSourceFileSizeTmp[2]) {
             case IMAGETYPE_GIF:
                 $sourceImage = imagecreatefromgif($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = true;
                 break;
             case IMAGETYPE_PNG:
                 $sourceImage = imagecreatefrompng($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = true;
                 break;
             case IMAGETYPE_BMP:
                 $sourceImage = CFile::ImageCreateFromBMP($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = false;
                 break;
             default:
                 $sourceImage = imagecreatefromjpeg($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = false;
                 break;
         }
         $sourceImageWidth = intval(imagesx($sourceImage));
         $sourceImageHeight = intval(imagesy($sourceImage));
         if ($sourceImageWidth > 0 && $sourceImageHeight > 0) {
             if ($arSize["width"] <= 0 || $arSize["height"] <= 0) {
                 $arSize["width"] = $sourceImageWidth;
                 $arSize["height"] = $sourceImageHeight;
             }
             CFile::ScaleImage($sourceImageWidth, $sourceImageHeight, $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
             if ($bNeedCreatePicture) {
                 if (CFile::IsGD2()) {
                     $picture = ImageCreateTrueColor($arDestinationSize["width"], $arDestinationSize["height"]);
                     if ($arSourceFileSizeTmp[2] == IMAGETYPE_PNG) {
                         $transparentcolor = imagecolorallocatealpha($picture, 0, 0, 0, 127);
                         imagefilledrectangle($picture, 0, 0, $arDestinationSize["width"], $arDestinationSize["height"], $transparentcolor);
                         imagealphablending($picture, false);
                         imagecopyresampled($picture, $sourceImage, 0, 0, $arSourceSize["x"], $arSourceSize["y"], $arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
                         imagealphablending($picture, true);
                     } elseif ($arSourceFileSizeTmp[2] == IMAGETYPE_GIF) {
                         imagepalettecopy($picture, $sourceImage);
                         //Save transparency for GIFs
                         $transparentcolor = imagecolortransparent($sourceImage);
                         if ($transparentcolor >= 0 && $transparentcolor < imagecolorstotal($sourceImage)) {
                             $RGB = imagecolorsforindex($sourceImage, $transparentcolor);
//.........这里部分代码省略.........
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:101,代码来源:file.php

示例7: UnpackFileArchive

 function UnpackFileArchive($strfile, $path_to)
 {
     global $APPLICATION;
     $res = true;
     $arcname = CTempFile::GetFileName(md5(uniqid(rand(), true)) . '.tar.gz');
     CheckDirPath($arcname);
     if (file_put_contents($arcname, $strfile) !== false) {
         include_once dirname(__FILE__) . '/tar_gz.php';
         $ob = new CArchiver($arcname);
         CheckDirPath($_SERVER['DOCUMENT_ROOT'] . $path_to);
         $res = $ob->extractFiles($_SERVER['DOCUMENT_ROOT'] . $path_to);
         if (!$res && is_object($APPLICATION)) {
             $arErrors = $ob->GetErrors();
             if (count($arErrors)) {
                 $strError = "";
                 foreach ($arErrors as $error) {
                     $strError .= $error[1] . "<br>";
                 }
                 $e = new CApplicationException($strError);
                 $APPLICATION->ThrowException($e);
             }
         }
     }
     return $res;
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:25,代码来源:controller_member.php

示例8: Add

 function Add($arFields, $bWorkFlow = false, $bUpdateSearch = true, $bResizePictures = false)
 {
     global $DB, $USER;
     $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]);
     $bWorkFlow = $bWorkFlow && is_array($arIBlock) && $arIBlock["WORKFLOW"] != "N" && CModule::IncludeModule("workflow");
     $bBizProc = is_array($arIBlock) && $arIBlock["BIZPROC"] == "Y" && IsModuleInstalled("bizproc");
     if (array_key_exists("BP_PUBLISHED", $arFields)) {
         if ($bBizProc) {
             if ($arFields["BP_PUBLISHED"] == "Y") {
                 $arFields["WF_STATUS_ID"] = 1;
                 $arFields["WF_NEW"] = false;
             } else {
                 $arFields["WF_STATUS_ID"] = 2;
                 $arFields["WF_NEW"] = "Y";
                 $arFields["BP_PUBLISHED"] = "N";
             }
         } else {
             unset($arFields["BP_PUBLISHED"]);
         }
     }
     if (array_key_exists("IBLOCK_SECTION_ID", $arFields)) {
         if (!array_key_exists("IBLOCK_SECTION", $arFields)) {
             $arFields["IBLOCK_SECTION"] = array($arFields["IBLOCK_SECTION_ID"]);
         } elseif (is_array($arFields["IBLOCK_SECTION"]) && !in_array($arFields["IBLOCK_SECTION_ID"], $arFields["IBLOCK_SECTION"])) {
             unset($arFields["IBLOCK_SECTION_ID"]);
         }
     }
     $strWarning = "";
     if ($bResizePictures) {
         $arDef = $arIBlock["FIELDS"]["PREVIEW_PICTURE"]["DEFAULT_VALUE"];
         if ($arDef["FROM_DETAIL"] === "Y" && is_array($arFields["DETAIL_PICTURE"]) && $arFields["DETAIL_PICTURE"]["size"] > 0 && ($arDef["UPDATE_WITH_DETAIL"] === "Y" || $arFields["PREVIEW_PICTURE"]["size"] <= 0)) {
             $arNewPreview = $arFields["DETAIL_PICTURE"];
             $arNewPreview["COPY_FILE"] = "Y";
             if (isset($arFields["PREVIEW_PICTURE"]) && is_array($arFields["PREVIEW_PICTURE"]) && isset($arFields["PREVIEW_PICTURE"]["description"])) {
                 $arNewPreview["description"] = $arFields["PREVIEW_PICTURE"]["description"];
             }
             $arFields["PREVIEW_PICTURE"] = $arNewPreview;
         }
         if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["SCALE"] === "Y") {
             $arNewPicture = CIBlock::ResizePicture($arFields["PREVIEW_PICTURE"], $arDef);
             if (is_array($arNewPicture)) {
                 $arNewPicture["description"] = $arFields["PREVIEW_PICTURE"]["description"];
                 $arFields["PREVIEW_PICTURE"] = $arNewPicture;
             } elseif ($arDef["IGNORE_ERRORS"] !== "Y") {
                 unset($arFields["PREVIEW_PICTURE"]);
                 $strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE") . ": " . $arNewPicture . "<br>";
             }
         }
         if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") {
             if (strlen($arFields["PREVIEW_PICTURE"]["tmp_name"]) > 0 && ($arFields["PREVIEW_PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PREVIEW_PICTURE"]["copy"])) {
                 $tmp_name = CTempFile::GetFileName(basename($arFields["PREVIEW_PICTURE"]["tmp_name"]));
                 CheckDirPath($tmp_name);
                 copy($arFields["PREVIEW_PICTURE"]["tmp_name"], $tmp_name);
                 $arFields["PREVIEW_PICTURE"]["copy"] = true;
                 $arFields["PREVIEW_PICTURE"]["tmp_name"] = $tmp_name;
             }
             CIBLock::FilterPicture($arFields["PREVIEW_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"])));
         }
         if (array_key_exists("PREVIEW_PICTURE", $arFields) && is_array($arFields["PREVIEW_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") {
             if (strlen($arFields["PREVIEW_PICTURE"]["tmp_name"]) > 0 && ($arFields["PREVIEW_PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"] || $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PREVIEW_PICTURE"]["copy"])) {
                 $tmp_name = CTempFile::GetFileName(basename($arFields["PREVIEW_PICTURE"]["tmp_name"]));
                 CheckDirPath($tmp_name);
                 copy($arFields["PREVIEW_PICTURE"]["tmp_name"], $tmp_name);
                 $arFields["PREVIEW_PICTURE"]["copy"] = true;
                 $arFields["PREVIEW_PICTURE"]["tmp_name"] = $tmp_name;
             }
             CIBLock::FilterPicture($arFields["PREVIEW_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"]));
         }
         $arDef = $arIBlock["FIELDS"]["DETAIL_PICTURE"]["DEFAULT_VALUE"];
         if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["SCALE"] === "Y") {
             $arNewPicture = CIBlock::ResizePicture($arFields["DETAIL_PICTURE"], $arDef);
             if (is_array($arNewPicture)) {
                 $arNewPicture["description"] = $arFields["DETAIL_PICTURE"]["description"];
                 $arFields["DETAIL_PICTURE"] = $arNewPicture;
             } elseif ($arDef["IGNORE_ERRORS"] !== "Y") {
                 unset($arFields["DETAIL_PICTURE"]);
                 $strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE") . ": " . $arNewPicture . "<br>";
             }
         }
         if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_FILE"] === "Y") {
             if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PREVIEW_PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) {
                 $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
                 CheckDirPath($tmp_name);
                 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name);
                 $arFields["DETAIL_PICTURE"]["copy"] = true;
                 $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name;
             }
             CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_FILE_POSITION"], "type" => "file", "size" => "real", "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100), "file" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_FILE"])));
         }
         if (array_key_exists("DETAIL_PICTURE", $arFields) && is_array($arFields["DETAIL_PICTURE"]) && $arDef["USE_WATERMARK_TEXT"] === "Y") {
             if (strlen($arFields["DETAIL_PICTURE"]["tmp_name"]) > 0 && ($arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PREVIEW_PICTURE"]["tmp_name"] || $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])) {
                 $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
                 CheckDirPath($tmp_name);
                 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name);
                 $arFields["DETAIL_PICTURE"]["copy"] = true;
                 $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name;
             }
             CIBLock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array("name" => "watermark", "position" => $arDef["WATERMARK_TEXT_POSITION"], "type" => "text", "coefficient" => $arDef["WATERMARK_TEXT_SIZE"], "text" => $arDef["WATERMARK_TEXT"], "font" => $_SERVER["DOCUMENT_ROOT"] . Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]), "color" => $arDef["WATERMARK_TEXT_COLOR"]));
         }
     }
//.........这里部分代码省略.........
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:101,代码来源:iblockelement.php

示例9: ResizeImage

	function ResizeImage(&$arFile, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL)
	{
		$sourceFile = $arFile["tmp_name"];
		$destinationFile = CTempFile::GetFileName(basename($sourceFile));

		CheckDirPath($destinationFile);

		if (CFile::ResizeImageFile($sourceFile, $destinationFile, $arSize, $resizeType))
		{
			$arFile["tmp_name"] = $destinationFile;
			$arImageSize = CFile::GetImageSize($destinationFile);
			$arFile["type"] = $arImageSize["mime"];
			$arFile["size"] = filesize($arFile["tmp_name"]);

			return true;
		}

		return false;
	}
开发者ID:nProfessor,项目名称:Mytb,代码行数:19,代码来源:file.php

示例10: saveRawFilesToUF

 public static function saveRawFilesToUF($arAttachedFilesRaw, $ufCode, &$arFields)
 {
     static $isDiskEnabled = false;
     static $isWebDavEnabled = false;
     if ($isDiskEnabled === false) {
         $isDiskEnabled = \Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk') && ($storage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($GLOBALS["USER"]->GetID())) && ($folder = $storage->getFolderForUploadedFiles($GLOBALS["USER"]->GetID())) ? "Y" : "N";
     }
     if ($isWebDavEnabled === false) {
         $isWebDavEnabled = IsModuleInstalled('webdav') ? "Y" : "N";
     }
     if (empty($arFields[$ufCode])) {
         $arFields[$ufCode] = array();
     }
     $arRelation = array();
     foreach ($arAttachedFilesRaw as $attachedFileRow) {
         if (!empty($attachedFileRow["base64"]) && !empty($attachedFileRow["url"])) {
             $fileContent = base64_decode($attachedFileRow["base64"]);
             $arUri = parse_url($attachedFileRow["url"]);
             if (!empty($arUri) && !empty($arUri["path"])) {
                 $fileName = $arUri["path"];
             }
             if (!empty($fileContent) && !empty($fileName)) {
                 $fileName = CTempFile::GetFileName($fileName);
                 if (CheckDirPath($fileName)) {
                     file_put_contents($fileName, $fileContent);
                     $arFile = CFile::MakeFileArray($fileName);
                     if (is_array($arFile)) {
                         $resultId = false;
                         if ($isDiskEnabled == "Y") {
                             $file = $folder->uploadFile($arFile, array('NAME' => $arFile["name"], 'CREATED_BY' => $GLOBALS["USER"]->GetID()), array(), true);
                             if ($file) {
                                 $resultId = \Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX . $file->getId();
                             }
                         } elseif ($isWebDavEnabled == "Y") {
                             $webDavData = CWebDavIblock::getRootSectionDataForUser($GLOBALS["USER"]->GetID());
                             if (is_array($webDavData)) {
                                 $webDavObject = new CWebDavIblock($webDavData["IBLOCK_ID"], "", array("ROOT_SECTION_ID" => $webDavData["SECTION_ID"], "DOCUMENT_TYPE" => array("webdav", 'CIBlockDocumentWebdavSocnet', 'iblock_' . $webDavData['SECTION_ID'] . '_user_' . intval($GLOBALS["USER"]->GetID()))));
                                 if ($webDavObject) {
                                     $arParent = $webDavObject->GetObject(array("section_id" => $webDavObject->GetMetaID("DROPPED")));
                                     if (!$arParent["not_found"]) {
                                         $path = $webDavObject->_get_path($arParent["item_id"], false);
                                         $tmpName = str_replace(array(":", ".", "/", "\\"), "_", ConvertTimeStamp(time(), "FULL"));
                                         $tmpOptions = array("path" => str_replace("//", "/", $path . "/" . $tmpName));
                                         $arParent = $webDavObject->GetObject($tmpOptions);
                                         if ($arParent["not_found"]) {
                                             $rMKCOL = $webDavObject->MKCOL($tmpOptions);
                                             if (intval($rMKCOL) == 201) {
                                                 $webDavData["SECTION_ID"] = $webDavObject->arParams["changed_element_id"];
                                             }
                                         } else {
                                             $webDavData["SECTION_ID"] = $arParent['item_id'];
                                             if (!$webDavObject->CheckUniqueName($tmpName, $webDavData["SECTION_ID"], $tmpRes)) {
                                                 $path = $webDavObject->_get_path($webDavData["SECTION_ID"], false);
                                                 $tmpName = randString(6);
                                                 $tmpOptions = array("path" => str_replace("//", "/", $path . "/" . $tmpName));
                                                 $rMKCOL = $webDavObject->MKCOL($tmpOptions);
                                                 if (intval($rMKCOL) == 201) {
                                                     $webDavData["SECTION_ID"] = $webDavData->arParams["changed_element_id"];
                                                 }
                                             }
                                         }
                                     }
                                     $options = array("new" => true, 'dropped' => true, "arFile" => $arFile, "arDocumentStates" => false, "arUserGroups" => array_merge($webDavObject->USER["GROUPS"], array("Author")), "FILE_NAME" => $arFile["name"], "IBLOCK_ID" => $webDavData["IBLOCK_ID"], "IBLOCK_SECTION_ID" => $webDavData["SECTION_ID"], "USER_FIELDS" => array());
                                     $GLOBALS['USER_FIELD_MANAGER']->EditFormAddFields($webDavObject->GetUfEntity(), $options['USER_FIELDS']);
                                     $GLOBALS["DB"]->StartTransaction();
                                     if (!$webDavObject->put_commit($options)) {
                                         $GLOBALS["DB"]->Rollback();
                                     } else {
                                         $GLOBALS["DB"]->Commit();
                                         $resultId = $options['ELEMENT_ID'];
                                     }
                                 }
                             }
                         } else {
                             $resultId = CFile::SaveFile($arFile, $arFile["MODULE_ID"]);
                         }
                         if ($resultId) {
                             $arFields[$ufCode][] = $resultId;
                         }
                         if (!empty($attachedFileRow["id"])) {
                             $arRelation[$attachedFileRow["id"]] = $resultId;
                         }
                     }
                 }
             }
         }
     }
     if (!empty($arRelation)) {
         $arFields["DETAIL_TEXT"] = preg_replace_callback("/\\[DISK\\s+FILE\\s+ID\\s*=\\s*pseudo@([\\d]+)\\]/is" . BX_UTF_PCRE_MODIFIER, function ($matches) use($arRelation, $isDiskEnabled, $isWebDavEnabled) {
             if (isset($arRelation[intval($matches[1])])) {
                 if ($isDiskEnabled == "Y") {
                     return "[DISK FILE ID=" . $arRelation[intval($matches[1])] . "]";
                 } elseif ($isWebDavEnabled == "Y") {
                     return "[DOCUMENT ID=" . intval($arRelation[intval($matches[1])]) . "]";
                 } else {
                     return "[DISK FILE ID=pseudo@" . $matches[1] . "]";
                 }
             } else {
                 return "[DISK FILE ID=pseudo@" . $matches[1] . "]";
             }
//.........这里部分代码省略.........
开发者ID:Satariall,项目名称:izurit,代码行数:101,代码来源:log_tools.php

示例11: PUT

 function PUT(&$options)
 {
     WDUnpackCookie();
     $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] = is_string($_SESSION["WEBDAV_DATA"]["PUT_EMPTY"]) ? $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] : "";
     $_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"] = is_string($_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"]) ? $_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"] : "";
     $this->IsDir($options, true);
     if ($this->arParams["is_dir"] === true) {
         return "409 Conflict";
     }
     if ($this->arParams["parent_id"] === false) {
         return false;
     }
     $options["new"] = $this->arParams["not_found"] === true;
     $options["ELEMENT_ID"] = $this->arParams["item_id"];
     if (!$this->CheckWebRights("PUT", array('arElement' => $this->arParams))) {
         $this->ThrowAccessDenied(__LINE__);
         return false;
     }
     $options["FILE_NAME"] = !empty($this->arParams["file_name"]) ? $this->arParams["file_name"] : $this->arParams["basename"];
     $options["FILE_NAME"] = $this->CorrectName($options["FILE_NAME"]);
     $options["~path"] = $this->_udecode($options["path"]);
     $options["set_now"] = false;
     if (($_SERVER['REQUEST_METHOD'] == "PUT" || $_SERVER['REQUEST_METHOD'] == "LOCK") && intVal($options["content_length"]) <= 0) {
         // Sometimes file is uploaded in 2 steps: 1) PUT with content_length == 0, when PUT with content_length >= 0.
         $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] = $options["~path"];
         $options["set_now"] = true;
     }
     if (!empty($_SESSION["WEBDAV_DATA"]["PUT_EMPTY"]) && $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] != $options["~path"]) {
         if ($_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"] == $options["~path"]) {
         } elseif (substr($options["FILE_NAME"], 0, 2) == "._" && $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] == str_replace($options["FILE_NAME"], substr($options["FILE_NAME"], 2), $options["~path"])) {
             // Mac OS uploads in 4 PUT: <br>
             // 1. PUT with content_length == 0;
             // 2. PUT with content_length == 0 && file_name == "._".file_name;
             // 3. PUT with content_length >= 0 && file_name == "._".file_name;
             // 4. PUT with content_length >= 0.
             $_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"] = $options["~path"];
         } else {
             $_SESSION["WEBDAV_DATA"] = array();
         }
     }
     WDPackCookie();
     if (!empty($_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"]) && $_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"] == $options["~path"]) {
         "no need to check data";
     } elseif (!$options["set_now"] && !empty($_SESSION["WEBDAV_DATA"]["PUT_EMPTY"]) && $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] == $options["~path"]) {
         "no need to check data";
     } elseif (!$this->CheckWebRights("", $options = array_merge($options, array("action" => $this->arParams["not_found"] ? "create" : "edit", "arElement" => $this->arParams)), false)) {
         $this->ThrowAccessDenied(__LINE__);
         return false;
     } elseif ($this->check_creator && $this->arParams["is_file"] === true && $this->arParams["element_array"]["CREATED_BY"] != $GLOBALS["USER"]->GetID()) {
         $this->ThrowAccessDenied(__LINE__);
         return false;
     }
     $options["IBLOCK_SECTION_ID"] = $this->arParams["parent_id"];
     if ($this->arParams["parent_id"] <= 0 && $this->arRootSection) {
         $options["IBLOCK_SECTION_ID"] = $this->arRootSection["ID"];
     }
     $options["TMP_FILE"] = CTempFile::GetFileName($options["FILE_NAME"]);
     CheckDirPath($options["TMP_FILE"]);
     $fp = fopen($options["TMP_FILE"], "w");
     return $fp;
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:61,代码来源:iblock.php

示例12: createIBlock

 private static function createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId = null)
 {
     if (is_null($siteId)) {
         $siteId = \CSite::GetDefSite();
     }
     $db = \CIBlock::GetList(array(), array("IBLOCK_TYPE_ID" => $iblockType, "CODE" => $iblock["CODE"], "CHECK_PERMISSIONS" => "N", "SITE_ID" => $siteId));
     if ($res = $db->Fetch()) {
         return $res["ID"];
     }
     $fields = array("NAME" => $iblock["NAME"], "DESCRIPTION" => $iblock["DESCRIPTION"], "IBLOCK_TYPE_ID" => $iblockType, "SORT" => $iblock["SORT"], "CODE" => $iblock["CODE"], "WORKFLOW" => "N", "ELEMENTS_NAME" => $iblock["ELEMENTS_NAME"], "ELEMENT_NAME" => $iblock["ELEMENT_NAME"], "ELEMENT_ADD" => $iblock["ELEMENT_ADD"], "ELEMENT_EDIT" => $iblock["ELEMENT_EDIT"], "ELEMENT_DELETE" => $iblock["ELEMENT_DELETE"], "SECTIONS_NAME" => $iblock["SECTIONS_NAME"], "SECTION_NAME" => $iblock["SECTION_NAME"], "SECTION_ADD" => $iblock["SECTION_ADD"], "SECTION_EDIT" => $iblock["SECTION_EDIT"], "SECTION_DELETE" => $iblock["SECTION_DELETE"], "BIZPROC" => "Y", "SITE_ID" => array($siteId), "RIGHTS_MODE" => "E");
     if ($iblock["SOCNET_GROUP_ID"]) {
         $fields["SOCNET_GROUP_ID"] = $iblock["SOCNET_GROUP_ID"];
     }
     static $exts = array("image/jpeg" => "jpg", "image/png" => "png", "image/gif" => "gif");
     if (!empty($picture) && isset($exts[$pictureType])) {
         $fn = \CTempFile::GetFileName();
         Main\IO\Directory::createDirectory($fn);
         $fn .= md5(mt_rand()) . "." . $exts[$pictureType];
         $f = fopen($fn, "wb");
         fwrite($f, $picture);
         fclose($f);
         $fields["PICTURE"] = \CFile::MakeFileArray($fn);
     }
     $ob = new \CIBlock();
     $res = $ob->Add($fields);
     if ($res) {
         self::createIBlockRights($res);
         $list = new \CList($res);
         if (isset($iblock["~NAME_FIELD"])) {
             $list->UpdateField("NAME", $iblock["~NAME_FIELD"]);
         }
         $list->Save();
         \CLists::setLiveFeed(1, $res);
         return $res;
     }
     return 0;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:37,代码来源:importer.php

示例13: PUT

 /**
  * @param array $arResult From PUT(&$arResult)
  * @return string String like '204 No Content', '403 Forbidden', '404 Not Found' or file pointer if we have to load file
  */
 protected function PUT(&$arResult)
 {
     /** @var CDavRequest $request */
     $request = $this->request;
     //todo откуда мы узнаем хранилище относительно которого вести поиск?
     list($storage, $path) = $this->parsePath($request->getPath());
     if (!$storage) {
         return '404 Not Found';
     }
     $withoutFilename = explode('/', $path);
     $filename = array_pop($withoutFilename);
     $folderId = Driver::getInstance()->getUrlManager()->resolveFolderIdFromPath($storage, implode('/', $withoutFilename));
     if (!$folderId) {
         return '404 Not Found';
         //"409 Conflict"?
     }
     /** @var Folder $folder */
     $folder = Folder::loadById($folderId);
     if (!$folder) {
         return '404 Not Found';
         //"409 Conflict"?
     }
     /** @var File $file */
     $file = File::load(array('NAME' => $filename, 'PARENT_ID' => $folder->getRealObjectId()));
     $securityContext = $folder->getStorage()->getCurrentUserSecurityContext();
     if (!$file) {
         if (!$folder->canAdd($securityContext)) {
             return '403 Forbidden';
         }
         $tmpFile = CTempFile::GetFileName($filename);
         CheckDirPath($tmpFile);
         $fp = fopen($tmpFile, "w");
         $arResult['new'] = true;
         $arResult['filename'] = $filename;
         $arResult['tmpFile'] = $tmpFile;
         $arResult['targetFolder'] = $folder;
         return $fp;
     }
     $arResult['new'] = false;
     if (!$file->canUpdate($securityContext)) {
         return '403 Forbidden';
     }
     $tmpFile = CTempFile::GetFileName($filename);
     CheckDirPath($tmpFile);
     $fp = fopen($tmpFile, "w");
     $arResult['tmpFile'] = $tmpFile;
     $arResult['targetFolder'] = $folder;
     $arResult['file'] = $file;
     return $fp;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:54,代码来源:webdavserver.php

示例14: OnFileSave

 public static function OnFileSave(&$arFile, $strFileName, $strSavePath, $bForceMD5 = false, $bSkipExt = false)
 {
     if (!$arFile["tmp_name"] && !array_key_exists("content", $arFile)) {
         return false;
     }
     if (array_key_exists("bucket", $arFile)) {
         $bucket = $arFile["bucket"];
     } else {
         $bucket = CCloudStorage::FindBucketForFile($arFile, $strFileName);
     }
     if (!is_object($bucket)) {
         return false;
     }
     if (!$bucket->Init()) {
         return false;
     }
     $copySize = false;
     $subDir = "";
     $filePath = "";
     if (array_key_exists("content", $arFile)) {
         $arFile["tmp_name"] = CTempFile::GetFileName($arFile["name"]);
         CheckDirPath($arFile["tmp_name"]);
         $fp = fopen($arFile["tmp_name"], "ab");
         if ($fp) {
             fwrite($fp, $arFile["content"]);
             fclose($fp);
         }
     }
     if (array_key_exists("bucket", $arFile)) {
         $newName = bx_basename($arFile["tmp_name"]);
         $prefix = $bucket->GetFileSRC("/");
         $subDir = substr($arFile["tmp_name"], strlen($prefix));
         $subDir = substr($subDir, 0, -strlen($newName) - 1);
     } else {
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             if (COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y") {
                 $newName = CCloudStorage::translit($strFileName);
             } else {
                 $newName = $strFileName;
             }
         } else {
             $strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, ".");
             $newName = md5(uniqid(mt_rand(), true)) . $strFileExt;
         }
         //check for double extension vulnerability
         $newName = RemoveScriptExtension($newName);
         while (true) {
             $strRand = md5(mt_rand());
             $strRand = substr($strRand, 0, 3) . "/" . $strRand;
             if (substr($strSavePath, -1) == "/") {
                 $subDir = $strSavePath . $strRand;
             } else {
                 $subDir = $strSavePath . "/" . $strRand;
             }
             $subDir = ltrim($subDir, "/");
             $filePath = "/" . $subDir . "/" . $newName;
             if (!$bucket->FileExists($filePath)) {
                 break;
             }
         }
         $targetPath = $bucket->GetFileSRC("/");
         if (strpos($arFile["tmp_name"], $targetPath) === 0) {
             $arDbFile = array("SUBDIR" => "", "FILE_NAME" => substr($arFile["tmp_name"], strlen($targetPath)), "CONTENT_TYPE" => $arFile["type"]);
             $copyPath = $bucket->FileCopy($arDbFile, $filePath);
             if (!$copyPath) {
                 return false;
             }
             $copySize = $bucket->GetFileSize("/" . urldecode(substr($copyPath, strlen($targetPath))));
         } else {
             $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, false);
             if (is_array($imgArray) && $imgArray[2] == IMAGETYPE_JPEG) {
                 $exifData = CFile::ExtractImageExif($arFile["tmp_name"]);
                 if ($exifData && isset($exifData['Orientation'])) {
                     $properlyOriented = CFile::ImageHandleOrientation($exifData['Orientation'], $arFile["tmp_name"]);
                     if ($properlyOriented) {
                         $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95'));
                         if ($jpgQuality <= 0 || $jpgQuality > 100) {
                             $jpgQuality = 95;
                         }
                         imagejpeg($properlyOriented, $arFile["tmp_name"], $jpgQuality);
                     }
                 }
             }
             if (!$bucket->SaveFile($filePath, $arFile)) {
                 return false;
             }
         }
     }
     $arFile["HANDLER_ID"] = $bucket->ID;
     $arFile["SUBDIR"] = $subDir;
     $arFile["FILE_NAME"] = $newName;
     $arFile["WIDTH"] = 0;
     $arFile["HEIGHT"] = 0;
     if (array_key_exists("bucket", $arFile)) {
         $arFile["WIDTH"] = $arFile["width"];
         $arFile["HEIGHT"] = $arFile["height"];
         $arFile["size"] = $arFile["file_size"];
     } elseif ($copySize !== false) {
         $arFile["size"] = $copySize;
         $bucket->IncFileCounter($copySize);
//.........这里部分代码省略.........
开发者ID:rasuldev,项目名称:torino,代码行数:101,代码来源:storage.php

示例15: ResizePicture

 /**
  * <p>Функция выполняет масштабирование файла.</p> <p><b>Примечание</b>: обрабатываются только файлы JPEG, GIF и PNG (зависит от используемой библиотеки GD). Файл указанный в параметре arFile будет перезаписан. <br></p>
  *
  *
  *
  *
  * @param array $arFile  Массив описывающий файл. Это может быть элемент массива $_FILES[имя]
  * (или $HTTP_POST_FILES[имя]), а также результат функции <a
  * href="http://dev.1c-bitrix.ru/api_help/main/reference/cfile/makefilearray.php">CFile::MakeFileArray</a>.
  *
  *
  *
  * @param array $arResize  Массив параметров масштабирования. Содержит следующие ключи:
  * <br><ul> <li>WIDTH - целое число. Размер картинки будет изменен таким
  * образом, что ее ширина не будет превышать значения этого поля. <br>
  * </li> <li>HEIGHT - целое число. Размер картинки будет изменен таким
  * образом, что ее высота не будет превышать значения этого поля. </li>
  * <li>METHOD - возможные значения: resample или пусто. Значение поля равное
  * "resample" приведет к использованию функции масштабирования
  * imagecopyresampled, а не imagecopyresized. Это более качественный метод, но требует
  * больше серверных ресурсов. <br> </li> <li>COMPRESSION - целое от 0 до 100. Если
  * значение больше 0, то для изображений jpeg оно будет использовано
  * как параметр компрессии. 100 соответствует наилучшему качеству
  * при большем размере файла. </li> </ul> Параметры METHOD и COMPRESSION
  * применяются только если происходит изменение размера. Если
  * картинка вписывается в ограничения WIDTH и HEIGHT, то никаких действий
  * над файлом выполнено не будет. <br><br>
  *
  *
  *
  * @return array <p>Массив описывающий файл или строка с сообщением об ошибке.</p>
  *
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?<br>AddEventHandler("iblock", "OnBeforeIBlockElementAdd", Array("MyHandlers", "ResizeElementProperty"));<br>AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", Array("MyHandlers", "ResizeElementProperty"));<br><br>class MyHandlers<br>{<br>	function ResizeElementProperty(&amp;$arFields)<br>	{<br>		global $APPLICATION;<br>		//Код инфоблока свойство каторого нуждается в масштабировании<br>		$IBLOCK_ID = 1;<br>		//Идентификатор свойства<br>		$PROPERTY_ID = 15;<br>		//Наш инфоблок и значения свойства в наличии<br>		if(<br>			$arFields["IBLOCK_ID"] == $IBLOCK_ID<br>			&amp;&amp; is_array($arFields["PROPERTY_VALUES"])<br>			&amp;&amp; array_key_exists(15, $arFields["PROPERTY_VALUES"])<br>		)<br>		{<br>			foreach($arFields["PROPERTY_VALUES"][$PROPERTY_ID] as $key =&gt; $arFile)<br>			{<br>				//Изменяем размеры картинки<br>				$arNewFile = CIBlock::ResizePicture($arFile, array(<br>					"WIDTH" =&gt; 100,<br>					"HEIGHT" =&gt; 100,<br>					"METHOD" =&gt; "resample",<br>				));<br>				if(is_array($arNewFile))<br>					$arFields["PROPERTY_VALUES"][$PROPERTY_ID][$key] = $arNewFile;<br>				else<br>				{<br>					//Можно вернуть ошибку<br>					$APPLICATION-&gt;throwException("Ошибка масштабирования изображения в свойстве \"Файлы\":".$arNewFile);<br>					return false;<br>				}<br>			}<br>		}<br>	}<br>}<br>?&gt;
  * </pre>
  *
  *
  *
  * <h4>See Also</h4> 
  * <ul> <li><a href="http://dev.1c-bitrix.ru/api_help/main/reference/cfile/makefilearray.php">CFile::MakeFileArray</a></li>
  * <li><a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblock/SetFields.php">CIBlock::SetFields</a></li> </ul><a
  * name="examples"></a>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblock/ResizePicture.php
  * @author Bitrix
  */
 public static function ResizePicture($arFile, $arResize)
 {
     if (strlen($arFile["tmp_name"]) <= 0) {
         return $arFile;
     }
     if (array_key_exists("error", $arFile) && $arFile["error"] !== 0) {
         return GetMessage("IBLOCK_BAD_FILE_ERROR");
     }
     $file = $arFile["tmp_name"];
     if (!file_exists($file) && !is_file($file)) {
         return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");
     }
     $width = intval($arResize["WIDTH"]);
     $height = intval($arResize["HEIGHT"]);
     if ($width <= 0 && $height <= 0) {
         return $arFile;
     }
     $orig = CFile::GetImageSize($file, true);
     if (!is_array($orig)) {
         return GetMessage("IBLOCK_BAD_FILE_NOT_PICTURE");
     }
     if ($width > 0 && $orig[0] > $width || $height > 0 && $orig[1] > $height) {
         if ($arFile["COPY_FILE"] == "Y") {
             $new_file = CTempFile::GetFileName(basename($file));
             CheckDirPath($new_file);
             $arFile["copy"] = true;
             if (copy($file, $new_file)) {
                 $file = $new_file;
             } else {
                 return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");
             }
         }
         $width_orig = $orig[0];
         $height_orig = $orig[1];
         if ($width <= 0) {
             $width = $width_orig;
         }
         if ($height <= 0) {
             $height = $height_orig;
         }
         $height_new = $height_orig;
         if ($width_orig > $width) {
             $height_new = $width / $width_orig * $height_orig;
         }
         if ($height_new > $height) {
             $width = $height / $height_orig * $width_orig;
         } else {
             $height = $height_new;
         }
         $image_type = $orig[2];
//.........这里部分代码省略.........
开发者ID:ASDAFF,项目名称:bxApiDocs,代码行数:101,代码来源:iblock.php


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