Exemple #1
0
 public 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 (strlen($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;
             }
         }
     }
     $result = $bucket->FileCopy($arFile, $filePath);
     if ($result) {
         $bucket->IncFileCounter($arFile["FILE_SIZE"]);
         if (strlen($newPath)) {
             $arFile["FILE_NAME"] = bx_basename($filePath);
             $arFile["SUBDIR"] = substr($filePath, 1, -(strlen(bx_basename($filePath)) + 1));
         } else {
             $arFile["FILE_NAME"] = $newName;
         }
     }
     return $result;
 }