Beispiel #1
0
 public static function OnMakeFileArray($arSourceFile, &$arDestination)
 {
     if (!is_array($arSourceFile)) {
         $file = $arSourceFile;
         if (substr($file, 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"]) {
             $file = ltrim(substr($file, strlen($_SERVER["DOCUMENT_ROOT"])), "/");
         }
         if (!preg_match("/^http:\\/\\//", $file)) {
             return false;
         }
         $bucket = CCloudStorage::FindBucketByFile($file);
         if (!is_object($bucket)) {
             return false;
         }
         $filePath = substr($file, strlen($bucket->GetFileSRC("/")) - 1);
         $filePath = urldecode($filePath);
         $target = CFile::GetTempName('', bx_basename($filePath));
         $target = preg_replace("#[\\\\\\/]+#", "/", $target);
         if ($bucket->DownloadToFile($filePath, $target)) {
             $arDestination = $target;
         }
         return true;
     } else {
         if ($arSourceFile["HANDLER_ID"] <= 0) {
             return false;
         }
         $bucket = new CCloudStorageBucket($arSourceFile["HANDLER_ID"]);
         if (!$bucket->Init()) {
             return false;
         }
         $target = CFile::GetTempName('', $arSourceFile["FILE_NAME"]);
         $target = preg_replace("#[\\\\\\/]+#", "/", $target);
         if ($bucket->DownloadToFile($arSourceFile, $target)) {
             $arDestination["name"] = strlen($arSourceFile['ORIGINAL_NAME']) > 0 ? $arSourceFile['ORIGINAL_NAME'] : $arSourceFile['FILE_NAME'];
             $arDestination["size"] = $arSourceFile['FILE_SIZE'];
             $arDestination["type"] = $arSourceFile['CONTENT_TYPE'];
             $arDestination["description"] = $arSourceFile['DESCRIPTION'];
             $arDestination["tmp_name"] = $target;
         }
         return true;
     }
 }