function DownloadToFile($arBucket, $arFile, $filePath) { $io = CBXVirtualIo::GetInstance(); $obRequest = new CHTTP(); $obRequest->follow_redirect = true; return $obRequest->Download($this->GetFileSRC($arBucket, $arFile), $io->GetPhysicalName($filePath)); }
function MakeFileArray($path, $mimetype = false) { $io = CBXVirtualIo::GetInstance(); $arFile = array(); if (intval($path) > 0) { $res = CFile::GetByID($path); if ($ar = $res->Fetch()) { $bExternalStorage = false; foreach (GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ar, &$arFile))) { $bExternalStorage = true; break; } } if (!$bExternalStorage) { $arFile["name"] = strlen($ar['ORIGINAL_NAME']) > 0 ? $ar['ORIGINAL_NAME'] : $ar['FILE_NAME']; $arFile["size"] = $ar['FILE_SIZE']; $arFile["type"] = $ar['CONTENT_TYPE']; $arFile["description"] = $ar['DESCRIPTION']; $arFile["tmp_name"] = $io->GetPhysicalName(preg_replace("#[\\\\\\/]+#", "/", $_SERVER['DOCUMENT_ROOT'] . '/' . COption::GetOptionString('main', 'upload_dir', 'upload') . '/' . $ar['SUBDIR'] . '/' . $ar['FILE_NAME'])); } return $arFile; } } $path = preg_replace("#(?<!:)[\\\\\\/]+#", "/", $path); if (strlen($path) == 0 || $path == "/") { return NULL; } if (preg_match("#^(http[s]?)://#", $path)) { $temp_path = ''; $bExternalStorage = false; foreach (GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($path, &$temp_path))) { $bExternalStorage = true; break; } } if (!$bExternalStorage) { $temp_path = CFile::GetTempName('', bx_basename($path)); $ob = new CHTTP(); $ob->follow_redirect = true; if ($ob->Download($path, $temp_path)) { $arFile = CFile::MakeFileArray($temp_path); } } elseif ($temp_path) { $arFile = CFile::MakeFileArray($temp_path); } } elseif (preg_match("#^(ftp[s]?|php)://#", $path)) { if ($fp = fopen($path, "rb")) { $content = ""; while (!feof($fp)) { $content .= fgets($fp, 4096); } if (strlen($content) > 0) { $temp_path = CFile::GetTempName('', bx_basename($path)); if (RewriteFile($temp_path, $content)) { $arFile = CFile::MakeFileArray($temp_path); } } fclose($fp); } } else { if (!file_exists($path)) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) { $path = $_SERVER["DOCUMENT_ROOT"] . $path; } else { return NULL; } } if (is_dir($path)) { return NULL; } $arFile["name"] = $io->GetLogicalName(bx_basename($path)); $arFile["size"] = filesize($path); $arFile["tmp_name"] = $path; $arFile["type"] = $mimetype; if (strlen($arFile["type"]) <= 0) { $arFile["type"] = CFile::GetContentType($path, true); } } if (strlen($arFile["type"]) <= 0) { $arFile["type"] = "unknown"; } return $arFile; }
function Scan($path) { $this->path = $path; if ($arCloudFiles = CBackup::GetBucketFileList($this->id, $path)) { foreach ($arCloudFiles['file'] as $k => $file) { if ($this->last_bucket_path) { if ($path . '/' . $file == $this->last_bucket_path) { $this->last_bucket_path = ''; } else { continue; } } $name = $this->path = $path . '/' . $file; if (!haveTime()) { // Сохраняется путь файла, который еще предстоит сохранить, TODO: пошаговое скачивание больших файлов return false; } $HTTP = new CHTTP(); if ($HTTP->Download($this->obBucket->GetFileSRC(array("URN" => $name)), DOCUMENT_ROOT . BX_ROOT . '/backup/clouds/' . $this->id . $name)) { $this->download_size += $arCloudFiles['file_size'][$k]; $this->download_cnt++; } else { $this->arSkipped[] = $name; } } } foreach ($arCloudFiles['dir'] as $dir) { if ($this->last_bucket_path) { if ($path . '/' . $dir == $this->last_bucket_path) { $this->last_bucket_path = ''; } elseif (strpos($this->last_bucket_path, $path . '/' . $dir) !== 0) { continue; } } if ($path . '/' . $dir == '/bitrix/backup') { continue; } if ($path . '/' . $dir == '/tmp') { continue; } if (!$this->Scan($path . '/' . $dir)) { // partial return false; } } return true; }
function check_ca_file() { if (file_exists($this->cafile)) unlink($this->cafile); CheckDirPath($this->cafile); $ob = new CHTTP(); $ob->http_timeout = 5; if ($ob->Download('http://www.bitrixsoft.com/upload/lib/cafile.pem', $this->cafile) && is_file($this->cafile) && filesize($this->cafile) > 0) return true; return $this->Result(null, GetMessage("MAIN_SC_NO_ACCESS").'"'); }
public function Scan($path) { $this->path = $path; if ($arCloudFiles = CBackup::GetBucketFileList($this->id, $path)) { foreach($arCloudFiles['file'] as $k=>$file) { if ($this->last_bucket_path) { if ($path.'/'.$file == $this->last_bucket_path) $this->last_bucket_path = ''; else continue; } $name = $this->path = $path.'/'.$file; if (!haveTime()) // Сохраняется путь файла, который еще предстоит сохранить, TODO: пошаговое скачивание больших файлов return false; $HTTP = new CHTTP; if ($HTTP->Download($this->obBucket->GetFileSRC(array("URN" => $name)), DOCUMENT_ROOT.BX_ROOT.'/backup/clouds/'.$this->id.$name)) { $this->download_size += $arCloudFiles['file_size'][$k]; $this->download_cnt++; } else $this->arSkipped[] = $name; } } foreach($arCloudFiles['dir'] as $dir) { if ($this->last_bucket_path) { if ($path.'/'.$dir == $this->last_bucket_path) $this->last_bucket_path = ''; elseif (strpos($this->last_bucket_path, $path.'/'.$dir) !== 0) continue; } if ($path.'/'.$dir == '/bitrix/backup') continue; if ($path.'/'.$dir == '/tmp') continue; if (!$this->Scan($path.'/'.$dir)) // partial return false; } return true; }