Esempio n. 1
0
                            ?>
<script>
							readFileChunk(<?php 
                            echo $bytes;
                            ?>
, <?php 
                            echo min($fileSize - 1, $bytes + $PHPchunkSize - 1);
                            ?>
);
						</script><?php 
                        } else {
                            $ar = CFile::MakeFileArray($absPath);
                            if (!is_array($ar) || !isset($ar["tmp_name"])) {
                                $strError = GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "e11"));
                            } else {
                                $res = $obBucket->SaveFile($filePath, $ar);
                                if ($res) {
                                    $bytes = $fileSize;
                                    $moveResult = CCloudStorage::FILE_MOVED;
                                    $obBucket->IncFileCounter($fileSize);
                                } else {
                                    $strError = GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "e12"));
                                }
                                @unlink($absPath);
                            }
                        }
                    } else {
                        $obUpload = new CCloudStorageUpload($filePath);
                        if (!$obUpload->isStarted()) {
                            if ($obUpload->Start($obBucket->ID, $fileSize, $_REQUEST["file_type"])) {
                                $moveResult = CCloudStorage::FILE_PARTLY_UPLOADED;
Esempio n. 2
0
 /**
  * @param CCloudStorageBucket $obBucket
  * @param string $path
  * @return bool
  */
 public static function ResizeImageFileCheck($obBucket, $path)
 {
     global $DB;
     $path = preg_replace("/^https?:/i", "", $path);
     $q = $DB->Query("\n\t\t\tselect\n\t\t\t\tID\n\t\t\t\t,ERROR_CODE\n\t\t\t\t,TO_PATH\n\t\t\t\t,FROM_PATH\n\t\t\t\t,PARAMS\n\t\t\t\t," . $DB->DateToCharFunction("TIMESTAMP_X", "FULL") . " TIMESTAMP_X\n\t\t\tfrom b_clouds_file_resize\n\t\t\twhere TO_PATH = '" . $DB->ForSql($path) . "'\n\t\t");
     $task = $q->Fetch();
     if (!$task) {
         return false;
     }
     if ($task["ERROR_CODE"] !== "0") {
         if (MakeTimeStamp($task["TIMESTAMP_X"]) + 300 > time() + CTimeZone::GetOffset()) {
             return false;
         }
     }
     $tmpFile = CFile::MakeFileArray($task["FROM_PATH"]);
     if (!is_array($tmpFile) || !file_exists($tmpFile["tmp_name"])) {
         $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '1'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t");
         return false;
     }
     $arResizeParams = unserialize($task["PARAMS"]);
     if (!is_array($arResizeParams)) {
         $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '2'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t");
         return false;
     }
     $arSize = $arResizeParams[0];
     $resizeType = $arResizeParams[1];
     $arWaterMark = $arResizeParams[2];
     $jpgQuality = $arResizeParams[3];
     $arFilters = $arResizeParams[4];
     $to_path = CFile::GetTempName('', bx_basename($task["TO_PATH"]));
     if (!CFile::ResizeImageFile($tmpFile["tmp_name"], $to_path, $arSize, $resizeType, $arWaterMark, $jpgQuality, $arFilters)) {
         $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '3'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t");
         return false;
     }
     $fileToStore = CFile::MakeFileArray($to_path);
     $baseURL = preg_replace("/^https?:/i", "", $obBucket->GetFileSRC("/"));
     $pathToStore = substr($task["TO_PATH"], strlen($baseURL) - 1);
     if (!$obBucket->SaveFile(urldecode($pathToStore), $fileToStore)) {
         $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '4'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t");
         return false;
     }
     $DB->Query("\n\t\t\tUPDATE b_clouds_file_resize\n\t\t\tSET ERROR_CODE = '0'\n\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t");
     return true;
 }
Esempio n. 3
0
	/**
	 * @param CCloudStorageBucket $obBucket
	 * @param string $path
	 * @return bool
	 */
	function ResizeImageFileCheck($obBucket, $path)
	{
		global $DB;
		$path = preg_replace("/^https?:/i", "", $path);
		$q = $DB->Query("
			select
				ID
				,ERROR_CODE
				,TO_PATH
				,FROM_PATH
				,PARAMS
				,".$DB->DateToCharFunction("TIMESTAMP_X", "FULL")." TIMESTAMP_X
			from b_clouds_file_resize
			where TO_PATH = '".$DB->ForSql($path)."'
		");
		$task = $q->Fetch();
		if (!$task)
			return false;

		//File in the Sky with Diamonds
		if ($task["ERROR_CODE"] == 9)
		{
			return true;
		}

		//Fatal error
		if ($task["ERROR_CODE"] >= 20)
		{
			return false;
		}

		//Recoverable error
		if ($task["ERROR_CODE"] >= 10 && $task["ERROR_CODE"] < 20)
		{
			if ((MakeTimeStamp($task["TIMESTAMP_X"]) + 300/*5min*/) > (time() + CTimeZone::GetOffset()))
				return false;
		}

		$DB->Query("
			UPDATE b_clouds_file_resize
			SET ERROR_CODE = '11'
			WHERE ID = ".$task["ID"]."
		");

		$tmpFile = CFile::MakeFileArray($task["FROM_PATH"]);
		if (!is_array($tmpFile) || !file_exists($tmpFile["tmp_name"]))
		{
			$DB->Query("
				UPDATE b_clouds_file_resize
				SET ERROR_CODE = '22'
				WHERE ID = ".$task["ID"]."
			");
			return false;
		}

		$arResizeParams = unserialize($task["PARAMS"]);
		if (!is_array($arResizeParams))
		{
			$DB->Query("
				UPDATE b_clouds_file_resize
				SET ERROR_CODE = '23'
				WHERE ID = ".$task["ID"]."
			");
			return false;
		}

		$DB->Query("
			UPDATE b_clouds_file_resize
			SET ERROR_CODE = '14'
			WHERE ID = ".$task["ID"]."
		");

		$arSize = $arResizeParams[0];
		$resizeType = $arResizeParams[1];
		$arWaterMark = $arResizeParams[2];
		$jpgQuality = $arResizeParams[3];
		$arFilters = $arResizeParams[4];

		$to_path = CFile::GetTempName('', bx_basename($task["TO_PATH"]));

		if (!CFile::ResizeImageFile($tmpFile["tmp_name"], $to_path, $arSize, $resizeType, $arWaterMark, $jpgQuality, $arFilters))
		{
			$DB->Query("
				UPDATE b_clouds_file_resize
				SET ERROR_CODE = '25'
				WHERE ID = ".$task["ID"]."
			");
			return false;
		}

		$DB->Query("
			UPDATE b_clouds_file_resize
			SET ERROR_CODE = '16'
			WHERE ID = ".$task["ID"]."
		");

		$fileToStore = CFile::MakeFileArray($to_path);
		if ($arResizeParams["type"] && !preg_match("/^image\\//", $fileToStore["type"]))
			$fileToStore["type"] = $arResizeParams["type"];

		$baseURL = preg_replace("/^https?:/i", "", $obBucket->GetFileSRC("/"));
		$pathToStore = substr($task["TO_PATH"], strlen($baseURL)-1);
		if (!$obBucket->SaveFile(urldecode($pathToStore), $fileToStore))
		{
			$DB->Query("
				UPDATE b_clouds_file_resize
				SET ERROR_CODE = '27'
				WHERE ID = ".$task["ID"]."
			");
			return false;
		}

		$DB->Query("
			UPDATE b_clouds_file_resize
			SET ERROR_CODE = '9'
			WHERE ID = ".$task["ID"]."
		");
		return true;
	}