示例#1
0
 protected static function handleFileByPath($hash, &$file)
 {
     $key = "default";
     if (self::resizePicture($file["files"][$key], array("method" => "resample"))) {
         clearstatcache();
         $file["files"][$key]["wasChangedOnServer"] = true;
         $file["files"][$key]["size"] = filesize($file["files"][$key]["tmp_name"]);
         $file["files"][$key]["sizeFormatted"] = \CFile::FormatSize($file["files"][$key]["size"]);
     }
     $docRoot = \CBXVirtualIo::GetInstance()->CombinePath($_SERVER["DOCUMENT_ROOT"]);
     $file["path"] = \CBXVirtualIo::GetInstance()->GetFile($file["files"][$key]["tmp_name"])->GetPathWithName();
     if (strpos($file["path"], $docRoot) === 0) {
         $file["path"] = str_replace("//", "/", "/" . substr($file["path"], strlen($docRoot)));
     }
     $file["files"][$key]["url"] = $file["files"][$key]["tmp_url"] = \Bitrix\Main\IO\Path::convertPhysicalToUri($file["path"]);
     $file["type"] = $file["files"][$key]["type"];
     return true;
 }
示例#2
0
	protected static function handleFileByPath($hash, &$file)
	{
		$key = "default";

		$path = $file["files"][$key]["tmp_name"];

		$io = \CBXVirtualIo::GetInstance();

		$newPath = substr($path, 0, (strlen($path) - strlen($key))).$file["name"];

		$f = $io->GetFile($path);
		$newF = $io->GetFile($newPath);

		if ((!$newF->IsExists() || $newF->unlink()) && $io->Rename($path, $newPath))
		{
			$f = $io->GetFile($newPath);
			$file["files"][$key]["tmp_name"] = $newPath;
		}

		if (self::resizePicture($file["files"][$key], array("method" => "resample")))
		{
			clearstatcache();
			$file["files"][$key]["wasChangedOnServer"] = true;
			$file["files"][$key]["size"] = filesize($file["files"][$key]["tmp_name"]);
			$file["files"][$key]["sizeFormatted"] = \CFile::FormatSize($file["files"][$key]["size"]);
		}

		$file["path"] = \Bitrix\Main\IO\Path::convertPhysicalToLogical($f->GetPathWithName());
		if (strpos($file["path"], $_SERVER["DOCUMENT_ROOT"]) === 0)
			$file["path"] = str_replace("//", "/", "/".substr($file["path"], strlen($_SERVER["DOCUMENT_ROOT"])));
		$file["uploadId"] = $file["path"];
		$file["files"][$key]["url"] =
		$file["files"][$key]["tmp_url"] = \Bitrix\Main\IO\Path::convertPhysicalToUri($file["path"]);

		$file["type"] = $file["files"][$key]["type"];
		return true;
	}