- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/zip.php
- Класс: CZip
- Вызов: CZip::_processFiles
private function _processFiles($arFileList, $addPath, $removePath)
{
$addPath = str_replace("\", "/", $addPath);
$removePath = str_replace("\", "/", $removePath);
if (!$this->zipfile)
{
$this->arErrors[] = ["ERR_DFILE", GetMessage("MAIN_ZIP_ERR_DFILE")];
return false;
}
if (!is_array($arFileList) || empty($arFileList))
{
return true;
}
$j = -1;
if (!isset($this->tempres))
{
$this->tempres = "started";
}
//files and directory scan
while ($j++ < count($arFileList) && ($this->tempres === "started"))
{
$filename = $arFileList[$j] ?? '';
if ($filename == '')
{
continue;
}
if (!file_exists($filename))
{
$this->arErrors[] = ["ERR_NO_FILE", str_replace("#FILE_NAME#", $filename, GetMessage("MAIN_ZIP_ERR_NO_FILE"))];
continue;
}
//is a file
if (!@is_dir($filename))
{
$filename = str_replace("//", "/", $filename);
//jumping to startFile, if it's specified
if ($this->startFile <> '')
{
if ($filename != $this->startFile)
{
//don't pack - jump to the next file
continue;
}
else
{
//if startFile is found, continue to pack files and folders without startFile, starting from next
$this->startFile = null;
continue;
}
}
//check product permissions
if ($this->checkPermissions)
{
if (!CBXArchive::HasAccess($filename, true))
{
continue;
}
}
if ($this->_haveTime())
{
if (!$this->_addFile($filename, $arFileHeaders, $this->add_path, $this->remove_path))
{
//$arErrors is filled in the _addFile method
$this->tempres = false;
}
else
{
//remember last file
$this->arPackedFiles[] = $filename;
$this->arHeaders[] = $arFileHeaders;
}
}
else
{
$this->tempres = 'continue';
return $this->tempres;
}
}
//if directory
else
{
if (!($handle = opendir($filename)))
{
$this->arErrors[] = ["ERR_DIR_OPEN_FAIL", str_replace("#DIR_NAME#", $filename, GetMessage("MAIN_ZIP_ERR_DIR_OPEN_FAIL"))];
continue;
}
if ($this->checkPermissions)
{
if (!CBXArchive::HasAccess($filename, false))
{
continue;
}
}
while (false !== ($dir = readdir($handle)))
{
if ($dir != "." && $dir != "..")
{
$arFileList_tmp = [];
if ($filename != ".")
{
$arFileList_tmp[] = $filename . '/' . $dir;
}
else
{
$arFileList_tmp[] = $dir;
}
$this->_processFiles($arFileList_tmp, $addPath, $removePath);
}
}
unset($arFileList_tmp);
unset($dir);
unset($handle);
}
}
return $this->tempres;
}