- Модуль: clouds
- Путь к файлу: ~/bitrix/modules/clouds/classes/general/storage.php
- Класс: CCloudStorage
- Вызов: CCloudStorage::OnFileCopy
static function OnFileCopy(&$arFile, $newPath = "")
{
if ($arFile["HANDLER_ID"] <= 0)
return false;
$bucket = new CCloudStorageBucket($arFile["HANDLER_ID"]);
if (!$bucket->Init())
return false;
if ($bucket->READ_ONLY == "Y")
return false;
$filePath = "";
$newName = "";
if($newPath <> '')
{
$filePath = "/".trim(str_replace("//", "/", $newPath), "/");
}
else
{
$strFileExt = strrchr($arFile["FILE_NAME"], ".");
while(true)
{
$newName = md5(uniqid(mt_rand(), true)).$strFileExt;
$filePath = "/".$arFile["SUBDIR"]."/".$newName;
if(!$bucket->FileExists($filePath))
{
break;
}
}
}
if ($newPath == '')
{
if ($arFile["EXTERNAL_ID"] == "")
{
$arFile["EXTERNAL_ID"] = md5(mt_rand());
}
BitrixCloudsFileSaveTable::startFileOperation(
$bucket->ID
,$arFile["SUBDIR"]
,$newName
,$arFile["EXTERNAL_ID"]
);
}
$result = $bucket->FileCopy($arFile, $filePath);
if ($result)
{
$copySize = $arFile["FILE_SIZE"];
$bucket->IncFileCounter($copySize);
BitrixCloudsFileSaveTable::setFileSize(
$bucket->ID
,$arFile["SUBDIR"]
,$newName
,$copySize
);
if($newPath <> '')
{
$arFile["FILE_NAME"] = bx_basename($filePath);
$arFile["SUBDIR"] = mb_substr($filePath, 1, -(mb_strlen(bx_basename($filePath)) + 1));
}
else
{
$arFile["FILE_NAME"] = $newName;
}
}
return $result;
}