if (strlen($arFile["name"]) <= 0 || $arFile["tmp_name"] == "none") { continue; } $arFile["name"] = GetFileName($arFile["name"]); $fname = ${"fname_" . $i}; if (strlen($fname) <= 0) { $fname = $arFile["name"]; } $path = GetDirPath($FILENAME); $pathto = Rel2Abs($path, $fname); $ext = GetFileExtension($pathto); if (!$USER->IsAdmin() && in_array($ext, $arExt)) { $message = new CAdminMessage(array("MESSAGE" => GetMessage("FLOW_ERROR"), "DETAILS" => GetMessage("FLOW_FILEUPLOAD_PHPERROR") . " \"" . $pathto . "\"", "TYPE" => "ERROR")); } elseif (!$USER->CanDoFileOperation('fm_edit_in_workflow', array($SITE_ID, $pathto))) { $message = new CAdminMessage(array("MESSAGE" => GetMessage("FLOW_ERROR"), "DETAILS" => GetMessage("FLOW_FILEUPLOAD_ACCESS_DENIED") . " \"" . $pathto . "\": " . GetMessage("FLOW_MIN_RIGHTS"), "TYPE" => "ERROR")); } elseif (!CBXVirtualIoFileSystem::ValidatePathString($pathto)) { $message = new CAdminMessage(array("MESSAGE" => GetMessage("FLOW_ERROR"), "DETAILS" => GetMessage("FLOW_FILE_NAME_NOT_VALID"), "TYPE" => "ERROR")); } else { $z = CWorkflow::GetFileByID($ID, $pathto); if ($zr = $z->Fetch()) { $message = new CAdminMessage(array("MESSAGE" => GetMessage("FLOW_ERROR"), "DETAILS" => str_replace("#FILE#", "{$pathto}", GetMessage("FLOW_FILE_ALREADY_EXIST")), "TYPE" => "ERROR")); } else { $temp_file = CWorkflow::GetUniqueFilename($pathto); $temp_dir = CWorkflow::GetTempDir(); if (!file_exists($temp_dir)) { mkdir($temp_dir, BX_DIR_PERMISSIONS); } $temp_path = $temp_dir . $temp_file; if (!copy($arFile["tmp_name"], $temp_path)) { $message = new CAdminMessage(array("MESSAGE" => GetMessage("FLOW_ERROR"), "DETAILS" => GetMessage("FLOW_FILEUPLOAD_FILE_CREATE_ERROR") . " \"" . $temp_path . "\"", "TYPE" => "ERROR")); } else {
function _mimetype($fspath) { $io = self::GetIo(); if ($io->DirectoryExists($fspath)) { return 'httpd/unix-directory'; } else { if (function_exists('mime_content_type') && $io->FileExists($fspath)) { $mime_type = mime_content_type(CBXVirtualIoFileSystem::ConvertCharset($fspath)); } } if (empty($mime_type)) { $mime_type = $this->get_mime_type($fspath); } return $mime_type; }
public function GetChildren() { $arResult = array(); if (!$this->IsExists()) return $arResult; if ($handle = opendir($this->GetPathWithNameEncoded())) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") continue; $pathDecoded = CBXVirtualIoFileSystem::ConvertCharset($this->GetPathWithNameEncoded()."/".$file, CBXVirtualIoFileSystem::directionDecode); if (is_dir($this->GetPathWithNameEncoded()."/".$file)) $arResult[] = new CBXVirtualDirectoryFileSystem($pathDecoded); else $arResult[] = new CBXVirtualFileFileSystem($pathDecoded); } closedir($handle); } return $arResult; }
function DeleteEx($path) { global $APPLICATION, $USER; CMain::InitPathVars($site, $path); if (strlen($path) <= 0) { return false; } $src = $_SERVER["DOCUMENT_ROOT"] . $path; $src = str_replace("//", "/", $src); if ($src == $_SERVER["DOCUMENT_ROOT"]) { return false; } $DOC_ROOT = CSite::GetSiteDocRoot($site); @set_time_limit(600); $io = CBXVirtualIo::GetInstance(); if (is_link($linkPath = CBXVirtualIoFileSystem::ConvertCharset($DOC_ROOT . $path))) { if (@unlink($linkPath)) { return; } else { return GetMessage("FILEMAN_FILEMAN_SYMLINK_DEL_ERROR") . " \"" . $path . "\".\n"; } } elseif ($io->DirectoryExists($DOC_ROOT . $path)) { //check rights if (!$USER->CanDoFileOperation('fm_delete_folder', array($site, $path))) { return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_DENY") . " \"" . $path . "\".\n"; } } else { return CFileman::DeleteFile(array($site, $path)); } $strWarning = ""; //get folder content $d = $io->GetDirectory($DOC_ROOT . $path); $arChildren = $d->GetChildren(); foreach ($arChildren as $child) { $fn = $child->GetName(); if ($child->IsDirectory()) { $strWarning .= CFileman::DeleteEx(array($site, $path . "/" . $fn)); } else { if ($fn == ".access.php") { continue; } $strWarning .= CFileman::DeleteFile(array($site, $path . "/" . $fn)); } } //delete first folder $strWarning .= CFileMan::DeleteDir(array($site, $path)); return $strWarning; }
public static function GetModifyTime($path) { $path = CBXVirtualIoFileSystem::ConvertCharset($path); if (file_exists($path)) { $stat = stat($path); return $stat["mtime"]; } return null; }
} // Building list while ($Elem = $db_DirContent->NavNext(true, "f_")) { $arPath = array($site, $Elem['ABS_PATH']); $fpath = $bSearch ? $Elem['ABS_PATH'] : ($path == "/" ? "" : $path) . "/" . $Elem["NAME"]; $fpathUrl = urlencode($fpath); for ($i = 0; $i < $cnt_resSites; $i++) { $dir = trim($resSites[$i]["DIR"], "/"); if (substr(trim($fpath, "/"), 0, strlen($dir)) == $dir) { $site = $resSites[$i]["ID"]; break; } } //$fname = $documentRoot.$path."/".$Elem["NAME"]; $fname = $documentRoot . $fpath; $fnameConverted = CBXVirtualIoFileSystem::ConvertCharset($fname); //http://www.jabber.bx/view.php?id=26893 $bIsDir = $io->DirectoryExists($fname); $arrIsDir[$fpath] = $bIsDir; if (!file_exists($fnameConverted)) { $lAdmin->AddGroupError(GetMessage("FILEMAN_ADMIN_FLIST_ERROR")); break; } if ($bSearch) { $f_NAME = $Elem['ABS_PATH']; } $showFieldIcon = ""; $showFieldText = ""; if ($Elem["TYPE"] == "D") { $showFieldIcon = "<a href=\"fileman_admin.php?" . $addUrl_s . "&site=" . urlencode($site) . "&path=" . $fpathUrl . "&show_perms_for=" . IntVal($show_perms_for) . "\" onclick=\"" . $sTableID . ".GetAdminList('fileman_admin.php?" . $addUrl_s . "&site=" . urlencode($site) . "&path=" . $fpathUrl . "&show_perms_for=" . IntVal($show_perms_for) . "', GALCallBack);return false;\"><span class='adm-submenu-item-link-icon fileman_icon_folder'></span></a>"; $showFieldText = "<a href=\"fileman_admin.php?" . $addUrl_s . "&site=" . urlencode($site) . "&path=" . $fpathUrl . "&show_perms_for=" . IntVal($show_perms_for) . "\" onclick=\"" . $sTableID . ".GetAdminList('fileman_admin.php?" . $addUrl_s . "&site=" . urlencode($site) . "&path=" . $fpathUrl . "&show_perms_for=" . IntVal($show_perms_for) . "', GALCallBack);return false;\">" . $f_NAME . "</a>";
if (strlen($strWarning) <= 0) { $flTmp = $io->GetFile($arFile["tmp_name"]); $fsize = $flTmp->GetFileSize(); $bufSize = 4194304; //4M session_write_close(); set_time_limit(0); header("Content-Type: application/force-download; name=\"" . $arFile["name"] . "\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); header("Content-Disposition: attachment; filename=\"" . $arFile["name"] . "\""); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header('Connection: close'); $arFile["tmp_name"] = CBXVirtualIoFileSystem::ConvertCharset($arFile["tmp_name"], CBXVirtualIoFileSystem::directionEncode); $f = fopen($arFile["tmp_name"], 'rb'); while (!feof($f)) { echo fread($f, $bufSize); ob_flush(); flush(); ob_end_clean(); } fclose($f); die; } $APPLICATION->SetTitle(GetMessage("FILEMAN_FILEDOWNLOAD") . " \"" . $arFile["name"] . "\""); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php"; ?> <font class="text"><?php echo $arFile["name"];
$path = str_replace(array("///", "//"), "/", $path); if (!$ob->CheckName($name)) { $arFileError[] = array("id" => "bad_element_name", "text" => str_replace(array("#NAME#", "#SIZE#"), array($arFile["name"], $arParams["UPLOAD_MAX_FILESIZE"]), GetMessage("WD_ERROR_BAD_ELEMENT_NAME"))); } elseif ($arParams["UPLOAD_MAX_FILESIZE_BYTE"] > 0 && $arFile["size"] > $arParams["UPLOAD_MAX_FILESIZE_BYTE"]) { $arFileError[] = array("id" => "max_file_size", "text" => str_replace(array("#NAME#", "#SIZE#"), array($arFile["name"], $arParams["UPLOAD_MAX_FILESIZE"]), GetMessage("WD_ERROR_UPLOAD_MAX_FILE_SIZE"))); } elseif ($ob::GetIo()->DirectoryExists($path)) { $arFileError[] = array("id" => "double_name_section", "text" => str_replace("#NAME#", $arFile["name"], GetMessage("WD_ERROR_DOUBLE_NAME_SECTION"))); } elseif ($_REQUEST["overview"] != "Y" && $ob::GetIo()->FileExists($path)) { if ($name != $arFile["name"]) { $arFileError[] = array("id" => "double_name_element", "text" => str_replace(array("#NAME#", "#TITLE#"), array($arFile["name"], $name), GetMessage("WD_ERROR_DOUBLE_NAME_TITLE"))); } else { $arFileError[] = array("id" => "double_name_element", "text" => str_replace("#NAME#", $arFile["name"], GetMessage("WD_ERROR_DOUBLE_NAME_ELEMENT"))); } } else { $options = array("path" => $path, "fopen" => "N"); $arFile['tmp_name'] = CBXVirtualIoFileSystem::ConvertCharset($arFile['tmp_name'], CBXVirtualIoFileSystem::directionDecode); if (!$ob->PUT($options)) { $err = $GLOBALS["APPLICATION"]->GetException(); $arFileError[] = array("id" => "bad_permission", "text" => is_object($err) ? $err->GetString() : "File has forbidden extention."); } elseif (!$ob::GetIo()->Copy($arFile["tmp_name"], $path)) { $arFileError[] = array("id" => "bad_upload", "text" => GetMessage("WD_ERROR_UPLOAD_FILE_NOT_LOAD")); } elseif (method_exists($ob, 'put_commit')) { $ob->put_commit($options); } } if (!empty($arFileError)) { $result = array("status" => "error", "error" => $arFileError); } else { $result = array("status" => "success"); } }
$val = $arItem["PROPERTY_" . $arParams["PATH_TO_FILE"] . "_VALUE"]; if (is_array($val)) { if (isset($val['path'])) { $PathToFile = $val['path']; } if (isset($val['duration'])) { $Duration = $val['duration']; } } else { $PathToFile = $arItem["PROPERTY_" . $arParams["PATH_TO_FILE"] . "_VALUE"]; } } if ($PathToFile == "") { continue; } if ($PathToFile && file_exists(CBXVirtualIoFileSystem::ConvertCharset($_SERVER["DOCUMENT_ROOT"] . "/" . $PathToFile)) && is_file(CBXVirtualIoFileSystem::ConvertCharset($_SERVER["DOCUMENT_ROOT"] . "/" . $PathToFile))) { $FileSize = filesize($_SERVER["DOCUMENT_ROOT"] . "/" . $PathToFile); if ($FileSize) { $FileSize = round(sprintf("%u", $FileSize) / 1024 / 1024, 2); } if ($FileSize <= 0) { $FileSize = ""; } $ext = strtolower(substr($PathToFile, -4)); if ($ext == ".wmv" || $ext == ".wma") { $FileType = "wmv"; } else { $FileType = "flv"; } } elseif (CModule::IncludeModule("clouds") && ($uri = CCloudStorage::FindFileURIByURN($PathToFile, "component:iblock.tv, iblock:" . $arParams["IBLOCK_ID"] . ", element: " . $arItem["ID"])) !== "") { $PathToFile = $uri;
function _processFileCallback($matches) { static $sImageAlign = ''; $bLink = false; if ($matches[1] == ':') { $bLink = true; } // if the internal file then get it $sFile = $sFileName = $sPath = trim($matches[3]); $bOur = false; if (is_numeric($sFile) && in_array($sFile, $this->arFile)) { $arFile = CFile::GetFileArray($sFile); if ($arFile != false) { $bOur = true; $sPath = $arFile['SRC']; $sFileName = $arFile['ORIGINAL_NAME']; } } else { if (isset($this->arVersionFile[strtolower($sFile)])) { $sPath = $this->arVersionFile[strtolower($sFile)]; $sFileName = $sFile; } else { if (!empty($this->arFile)) { $arFilter = array('@ID' => implode(',', $this->arFile)); $rsFile = CFile::GetList(array(), $arFilter); while ($arFile = $rsFile->Fetch()) { if ($arFile['ORIGINAL_NAME'] == $sFile) { $bOur = true; $sFile = $arFile['ID']; $sPath = CFile::GetFileSRC($arFile); $sFileName = $arFile['ORIGINAL_NAME']; break; } } } } } // if the image is processed as a picture $sName = bx_basename($sPath); if (CFile::IsImage($sName)) { if ($bOur) { $tmpName = $_SERVER["DOCUMENT_ROOT"] . $sPath; $imageFile = array("name" => $sFileName, "tmp_name" => CBXVirtualIoFileSystem::ConvertCharset($tmpName), "type" => CFile::GetContentType($tmpName)); $checkRes = CFile::CheckImageFile($imageFile); if ($checkRes != null) { return $checkRes; } if ($bLink) { $sReturn = '<a href="' . htmlspecialcharsbx($sPath) . '" title="' . ($s = htmlspecialcharsbx($sFileName)) . '">' . $s . '</a>'; } else { $sReturn = CFile::ShowImage($sFile, COption::GetOptionString('wiki', 'image_max_width', 600), COption::GetOptionString('wiki', 'image_max_height', 600), 'border="0" align="' . $sImageAlign . '"'); } } else { if ($bLink) { $sReturn = '<a href="' . htmlspecialcharsbx($sPath) . '" title="' . ($s = htmlspecialcharsbx($sName)) . '">' . $s . '</a>'; } else { $sReturn = '<img src="' . htmlspecialcharsbx($sPath) . '" alt="' . htmlspecialcharsbx($sFileName) . '"/>'; } } } else { if (strpos($sPath, 'http://') === 0) { $sReturn = ' [ <a href="' . htmlspecialcharsbx($sFile) . '" title="' . GetMessage('FILE_FILE_DOWNLOAD') . '">' . GetMessage('FILE_DOWNLOAD') . '</a> ] '; } else { $sReturn = '[' . GetMessage('FILE_NAME') . ':' . htmlspecialcharsbx(is_numeric($sFile) || empty($sFileName) ? $sFile : $sFileName) . ']'; } } return $sReturn; }
public static function GetFileContent($did, $fname, $wf_path = "", $site = false) { $err_mess = CAllWorkflow::err_mess() . "<br>Function: GetFileContent<br>Line: "; global $DB, $APPLICATION, $USER; $did = intval($did); // check if executable if ($USER->IsAdmin() || CBXVirtualIoFileSystem::ValidatePathString($fname) && !HasScriptExtension($fname)) { if ($did > 0) { // check if it is associated wtih document $z = CWorkflow::GetFileByID($did, $fname); // found one if ($zr = $z->Fetch()) { // get it's contents $path = CWorkflow::GetTempDir() . $zr["TEMP_FILENAME"]; if (file_exists($path)) { return $APPLICATION->GetFileContent($path); } } else { // lookup in database $strSql = "SELECT FILENAME, SITE_ID FROM b_workflow_document WHERE ID='{$did}'"; $y = $DB->Query($strSql, false, $err_mess . __LINE__); // found if ($yr = $y->Fetch()) { // get it's directory $path = GetDirPath($yr["FILENAME"]); // absolute path $pathto = Rel2Abs($path, $fname); $DOC_ROOT = CSite::GetSiteDocRoot($yr["SITE_ID"]); $path = $DOC_ROOT . $pathto; // give it another try $u = CWorkflow::GetFileByID($did, $pathto); // found if ($ur = $u->Fetch()) { // get it's contents $path = CWorkflow::GetTempDir() . $ur["TEMP_FILENAME"]; if (file_exists($path)) { return $APPLICATION->GetFileContent($path); } } elseif (file_exists($path)) { // get it's contents if ($USER->CanDoFileOperation('fm_view_file', array($yr["SITE_ID"], $pathto))) { return $APPLICATION->GetFileContent($path); } } } } } $DOC_ROOT = CSite::GetSiteDocRoot($site); // new one if (strlen($wf_path) > 0) { $pathto = Rel2Abs($wf_path, $fname); $path = $DOC_ROOT . $pathto; if (file_exists($path)) { // get it's contents if ($USER->CanDoFileOperation('fm_view_file', array($site, $pathto))) { $src = $APPLICATION->GetFileContent($path); return $src; } } } // still failed to find // get path $path = $DOC_ROOT . $fname; if (file_exists($path)) { // get it's contents if ($USER->CanDoFileOperation('fm_view_file', array($site, $fname))) { return $APPLICATION->GetFileContent($path); } } } else { return GetMessage("FLOW_ACCESS_DENIED_PHP_VIEW"); } }
"DEFAULT" => true, "ACTION" => "javascript:".$sTableID.".GetAdminList('fileman_admin.php?".$addUrl_s."&site=".$site."&path=".urlencode($arParsedPath["PREV"])."&show_perms_for=".IntVal($show_perms_for)."', GALCallBack);" ); $row->AddActions($arActions); } // Building list while($Elem = $db_DirContent->NavNext(true, "f_")) { $arPath = Array($site, $Elem['ABS_PATH']); $fpath = $bSearch ? $Elem['ABS_PATH'] : $path."/".$Elem["NAME"]; $fpathUrl = urlencode($fpath); //$fname = $documentRoot.$path."/".$Elem["NAME"]; $fname = $documentRoot.$fpath; $fnameConverted = CBXVirtualIoFileSystem::ConvertCharset($fname); //http://www.jabber.bx/view.php?id=26893 if(!file_exists($fnameConverted)) { $lAdmin->AddGroupError(GetMessage("FILEMAN_ADMIN_FLIST_ERROR")); break; } if ($bSearch) $f_NAME = $Elem['ABS_PATH']; $showFieldIcon = ""; $showFieldText = ""; if($Elem["TYPE"] == "D") { $showFieldIcon = "<a href=\"fileman_admin.php?".$addUrl_s."&site=".urlencode($site)."&path=".$fpathUrl."&show_perms_for=".IntVal($show_perms_for)."\" onclick=\"".$sTableID.".GetAdminList('fileman_admin.php?".$addUrl_s."&site=".urlencode($site)."&path=".$fpathUrl."&show_perms_for=".IntVal($show_perms_for)."', GALCallBack);return false;\"><span class='adm-submenu-item-link-icon fileman_icon_folder'></span></a>";