当前位置: 首页>>代码示例>>PHP>>正文


PHP GetFileName函数代码示例

本文整理汇总了PHP中GetFileName函数的典型用法代码示例。如果您正苦于以下问题:PHP GetFileName函数的具体用法?PHP GetFileName怎么用?PHP GetFileName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetFileName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CheckRights

 function CheckRights($method, $strong, &$path)
 {
     $result = true;
     if (!parent::CheckRights($method)) {
         $result = false;
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage('WD_ACCESS_DENIED'), 'ACCESS_DENIED');
     } elseif ($path != '') {
         $io = CBXVirtualIo::GetInstance();
         $path = $io->CombinePath($this->_udecode($path));
         $strFileName = GetFileName($path);
         $extention = "." . strtolower(GetFileExtension($strFileName));
         if (in_array($method, array("COPY", "MOVE", "PUT"))) {
             if (!$GLOBALS["USER"]->IsAdmin() && HasScriptExtension($strFileName)) {
                 $result = false;
                 $GLOBALS['APPLICATION']->ThrowException(GetMessage("WD_FILE_ERROR13"), "FORBIDDEN_EXTENTION");
             } elseif (IsFileUnsafe($strFileName) || $strFileName == "index.php") {
                 $result = false;
                 $GLOBALS['APPLICATION']->ThrowException(GetMessage("WD_FILE_ERROR14"), "FORBIDDEN_NAME");
             } elseif (!$io->ValidatePathString($io->CombinePath("/", $path)) || !$io->ValidateFilenameString($strFileName)) {
                 $result = false;
                 $GLOBALS['APPLICATION']->ThrowException(GetMessage("WD_FILE_ERROR14"), "FORBIDDEN_NAME");
             } elseif (in_array($extention, $this->arFileForbiddenExtentions["WRITE"])) {
                 $result = false;
                 $GLOBALS['APPLICATION']->ThrowException(GetMessage("WD_FILE_ERROR13"), "FORBIDDEN_EXTENTION");
             }
         } elseif (in_array($extention, $this->arFileForbiddenExtentions["READ"])) {
             $result = false;
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage('WD_ACCESS_DENIED'), 'ACCESS_DENIED');
         }
     }
     return $result;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:32,代码来源:file.php

示例2: SmiliesReplace

/**
 * Парсер смайликов.
 * @param  $text
 * @return void
 */
function SmiliesReplace(&$text)
{
    static $codes = null;
    if (!isset($codes)) {
        $codes = array();
        $smilies_dir = System::config('general/smilies_dir');
        $smilies = System::database()->Select('smilies');
        // Пусть отключенные смайлики тоже парсятся
        foreach ($smilies as $smile) {
            $sub_codes = explode(',', $smile['code']);
            $smile_file = SafeDB($smile['file'], 255, str);
            if ($smile['desc'] != '') {
                $title = SafeDB($smile['desc'], 255, str);
            } else {
                $title = SafeDB(GetFileName($smile_file, true), 255, str);
            }
            foreach ($sub_codes as $code) {
                $code = trim($code);
                if ($code != '') {
                    $codes[$code] = '<img src="' . RealPath2($smilies_dir . $smile_file) . '" title="' . $title . '">';
                }
            }
        }
    }
    $text = strtr($text, $codes);
}
开发者ID:agnyrussia,项目名称:linkorcms_mod_forms_file_support,代码行数:31,代码来源:smilies.php

示例3: FormsCheckType

function FormsCheckType($var, $typearr, &$error = null, &$filename = null)
{
    if ($typearr[1] == 'file') {
        $file_save_dir = 'uploads/forms';
        if (!is_dir($file_save_dir)) {
            mkdir($file_save_dir);
        }
        $UploadErrors = array(0 => '', 1 => 'Размер файла превышен', 2 => 'Размер файла превышен', 3 => 'Файл загружен только частично', 4 => 'Файл не был загружен.', 6 => 'Не найдена папка для временных файлов на сервере', 7 => 'Ошибка во время записи на диск', 8 => 'Загрузка файла была прервана расширением PHP', 9 => 'Ошибка во время записи на диск');
        if ($var['error'] == UPLOAD_ERR_OK) {
            $filename = Translit($var['name'], true);
            $ext = GetFileExt($filename);
            $name = GetFileName($filename, true);
            $file_path = $file_save_dir . '/' . $name . '_' . GenRandomString(8) . $ext;
            copy($var['tmp_name'], $file_path);
            return $file_path;
        } else {
            if ($var['error'] != 4) {
                $error = $UploadErrors[$var['error']];
            }
            return '';
        }
    }
    if ($typearr[2] == 'false') {
        $strip_tags = false;
    } else {
        $strip_tags = true;
    }
    $r = SafeEnv($var, (int) $typearr[0], (string) $typearr[1], $strip_tags);
    if ($r === false) {
        $r = '0';
    } elseif ($r === true) {
        $r = '1';
    }
    return $r;
}
开发者ID:agnyrussia,项目名称:linkorcms_mod_forms_file_support,代码行数:35,代码来源:forms.inc.php

示例4: __construct

 public function __construct($Url = '', $Utf8 = false)
 {
     if ($Url == '') {
         return;
     }
     $info = parse_url($Url);
     if ($info === false) {
         return;
     }
     if (isset($info['scheme'])) {
         $this->Protocol = $info['scheme'];
     }
     if (isset($info['host'])) {
         $this->Host = $info['host'];
     }
     if (isset($info['port'])) {
         $this->Port = $info['port'];
     }
     if (isset($info['user'])) {
         $this->User = $info['user'];
     }
     if (isset($info['pass'])) {
         $this->Password = $info['pass'];
     }
     if (isset($info['path'])) {
         $this->Path = GetPathName($info['path']);
         $this->Document = GetFileName($info['path']);
     }
     if (isset($info['fragment'])) {
         $this->Anchor = $info['fragment'];
     }
     if (isset($info['query'])) {
         parse_str($info['query'], $params);
         parent::__construct($params);
         if ($Utf8) {
             foreach ($this as $key => $value) {
                 $value = Utf8ToCp1251($value);
                 $this[$key] = $value;
             }
         }
     } else {
         parent::__construct();
     }
 }
开发者ID:agnyrussia,项目名称:linkorcms_mod_forms_file_support,代码行数:44,代码来源:url.class.php

示例5: GetFileNewName

function GetFileNewName($aid, $typeid, $timetag, $title, $ismake = 0, $rank = 0, $namerule = '', $typedir = '', $money = 0, $filename = '')
{
    global $cfg_arc_dirname;
    $articlename = GetFileName($aid, $typeid, $timetag, $title, $ismake, $rank, $namerule, $typedir, $money, $filename);
    if (ereg("\\?", $articlename)) {
        return $articlename;
    }
    if ($cfg_arc_dirname == 'Y' && ereg("/\$", $articlename)) {
        $articlename = $articlename . "index.html";
    }
    $slen = strlen($articlename) - 1;
    for ($i = $slen; $i >= 0; $i--) {
        if ($articlename[$i] == '/') {
            $subpos = $i;
            break;
        }
    }
    $okdir = substr($articlename, 0, $subpos);
    CreateDir($okdir);
    return $articlename;
}
开发者ID:klr2003,项目名称:sourceread,代码行数:21,代码来源:channelunit.func.php

示例6: import

 public static function import($arParams)
 {
     global $APPLICATION;
     // check fields
     $aMsg = array();
     $arParams['SET_ID'] = intval($arParams['SET_ID']);
     $arParams['IMPORT_IF_FILE_EXISTS'] = isset($arParams['IMPORT_IF_FILE_EXISTS']) && $arParams['IMPORT_IF_FILE_EXISTS'] == 'Y' ? true : false;
     if (isset($arParams['FILE']) && GetFileExtension($arParams['FILE']) != 'zip') {
         $aMsg["FILE_EXT"] = array("id" => "FILE_EXT", "text" => GetMessage("MAIN_SMILE_IMPORT_FILE_EXT_ERROR"));
     } else {
         if (!isset($arParams['FILE']) || !file_exists($arParams['FILE'])) {
             $aMsg["FILE"] = array("id" => "FILE", "text" => GetMessage("MAIN_SMILE_IMPORT_FILE_ERROR"));
         } else {
             if ($arParams['SET_ID'] <= 0) {
                 $aMsg["SET_ID"] = array("id" => "SET_ID", "text" => GetMessage("MAIN_SMILE_IMPORT_SET_ID_ERROR"));
             }
         }
     }
     if (!empty($aMsg)) {
         $e = new CAdminException($aMsg);
         $APPLICATION->ThrowException($e);
         return false;
     }
     $sUnpackDir = CTempFile::GetDirectoryName(1);
     CheckDirPath($sUnpackDir);
     /** @var IBXArchive $oArchiver */
     $oArchiver = CBXArchive::GetArchive($arParams['FILE'], "ZIP");
     $oArchiver->SetOptions(array("STEP_TIME" => 300));
     if (!$oArchiver->Unpack($sUnpackDir)) {
         $aMsg["UNPACK"] = array("id" => "UNPACK", "text" => GetMessage("MAIN_SMILE_IMPORT_UNPACK_ERROR"));
         $e = new CAdminException($aMsg);
         $APPLICATION->ThrowException($e);
         return false;
     }
     $arSmiles = array();
     if (file_exists($sUnpackDir . 'install.csv')) {
         $arLang = array();
         $db_res = CLanguage::GetList($b = "sort", $o = "asc");
         while ($res = $db_res->Fetch()) {
             if (file_exists($sUnpackDir . 'install_lang_' . $res["LID"] . '.csv')) {
                 $arSmiles = array();
                 $csvFile = new CCSVData();
                 $csvFile->LoadFile($sUnpackDir . 'install_lang_' . $res["LID"] . '.csv');
                 $csvFile->SetFieldsType("R");
                 $csvFile->SetFirstHeader(false);
                 while ($smile = $csvFile->Fetch()) {
                     if (defined('BX_UTF') && BX_UTF && $res["LID"] == 'ru') {
                         $smile[1] = $APPLICATION->ConvertCharset($smile[1], 'windows-1251', 'utf-8');
                     }
                     $arLang[$smile[0]][$res["LID"]] = $smile[1];
                 }
             }
         }
         $csvFile = new CCSVData();
         $csvFile->LoadFile($sUnpackDir . 'install.csv');
         $csvFile->SetFieldsType("R");
         $csvFile->SetFirstHeader(false);
         while ($smileRes = $csvFile->Fetch()) {
             $smile = array('TYPE' => $smileRes[0], 'CLICKABLE' => $smileRes[1] == 'Y' ? 'Y' : 'N', 'SORT' => intval($smileRes[2]), 'IMAGE' => $smileRes[3], 'IMAGE_WIDTH' => intval($smileRes[4]), 'IMAGE_HEIGHT' => intval($smileRes[5]), 'IMAGE_DEFINITION' => in_array($smileRes[6], array(self::IMAGE_SD, self::IMAGE_HD, self::IMAGE_UHD)) ? $smileRes[6] : ($smileRes[6] == 'Y' ? self::IMAGE_HD : self::IMAGE_SD), 'HIDDEN' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[7] : 'N', 'IMAGE_LANG' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[8] : $smileRes[7], 'TYPING' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[9] : $smileRes[8]);
             if (!in_array($smile['TYPE'], array(CSmile::TYPE_SMILE, CSmile::TYPE_ICON))) {
                 continue;
             }
             $smile['IMAGE'] = GetFileName($smile['IMAGE']);
             $imgArray = CFile::GetImageSize($sUnpackDir . $smile['IMAGE']);
             if (!is_array($imgArray)) {
                 continue;
             }
             $arInsert = array('TYPE' => $smile['TYPE'], 'SET_ID' => $arParams['SET_ID'], 'CLICKABLE' => $smile['CLICKABLE'], 'SORT' => $smile['SORT'], 'IMAGE' => $smile['IMAGE'], 'IMAGE_WIDTH' => $smile['IMAGE_WIDTH'], 'IMAGE_HEIGHT' => $smile['IMAGE_HEIGHT'], 'IMAGE_DEFINITION' => $smile['IMAGE_DEFINITION'], 'HIDDEN' => $smile['HIDDEN'], 'TYPING' => $smile['TYPING']);
             if (isset($arLang[$smile['IMAGE_LANG']])) {
                 $arInsert['LANG'] = $arLang[$smile['IMAGE_LANG']];
             }
             $arSmiles[] = $arInsert;
         }
     } else {
         $smileSet = CSmileSet::getById($arParams['SET_ID']);
         if ($handle = @opendir($sUnpackDir)) {
             $sort = 300;
             while (($file = readdir($handle)) !== false) {
                 if ($file == "." || $file == "..") {
                     continue;
                 }
                 if (is_file($sUnpackDir . $file)) {
                     $imgArray = CFile::GetImageSize($sUnpackDir . $file);
                     if (is_array($imgArray)) {
                         $smileHR = self::IMAGE_SD;
                         $smileType = CSmile::TYPE_SMILE;
                         $smileCode = GetFileNameWithoutExtension($file);
                         if (strpos($file, 'smile_') !== false && strpos($file, 'smile_') == 0) {
                             $smileCode = substr($smileCode, 6);
                         } elseif (strpos($file, 'smile') !== false && strpos($file, 'smile') == 0) {
                             $smileCode = substr($smileCode, 5);
                         } elseif (strpos($file, 'icon_') !== false && strpos($file, 'icon_') == 0) {
                             $smileType = CSmile::TYPE_ICON;
                             $smileCode = substr($smileCode, 5);
                         } else {
                             if (strpos($file, 'icon') !== false && strpos($file, 'icon') == 0) {
                                 $smileType = CSmile::TYPE_ICON;
                                 $smileCode = substr($smileCode, 4);
                             }
                         }
//.........这里部分代码省略.........
开发者ID:andy-profi,项目名称:bxApiDocs,代码行数:101,代码来源:smile.php

示例7: GetFileName

 function GetFileName($path)
 {
     return GetFileName($path);
 }
开发者ID:Satariall,项目名称:izurit,代码行数:4,代码来源:fileman.php

示例8: elseif

} elseif (SITE_TEMPLATE_ID == "bitrix24") {
    $sType = "b24_template";
}
$arResult = array("SITE_TYPE" => $sType, "ICON" => "empty.jpg", "F_SIZE" => 0, "DESCRIPTION" => "", "FILE_NOT_FOUND" => false, "PASSWORD" => "NOT");
$hash = CWebDavExtLinks::GetHashFromURL();
if ($hash === false) {
    ShowError(GetMessage('WD_MODULE_IS_FILE_NOT_FOUND'));
    return 0;
}
//not set default value to in getList LINK_TYPE
$resF = CWebDavExtLinks::GetList(array("HASH" => $hash, "ACTUAL" => true, 'LINK_TYPE' => null), array("URL", "RESOURCE_TYPE", "FOLDER", "IBLOCK_TYPE", "IBLOCK_ID", "BASE_URL", "HASH", "CREATION_DATE", "USER_ID", "SALT", "PASSWORD", "LIFETIME", "F_SIZE", "DESCRIPTION", "ROOT_SECTION_ID", "URL_HASH", 'SINGLE_SESSION', 'LINK_TYPE', 'DOWNLOAD_COUNT', 'VERSION_ID', 'ELEMENT_ID', 'FILE_ID'));
$arGetListRes = null;
if ($arF = $resF->Fetch()) {
    $arGetListRes = $arF;
    $arResult["HASH"] = $hash;
    $arResult["NAME"] = GetFileName($arF["URL"]);
    $arResult["ICON"] = CWebDavExtLinks::GetExtensionIcon($arF["URL"]);
    $arResult["F_SIZE"] = $arF["F_SIZE"];
    $arResult["DESCRIPTION"] = $arF["DESCRIPTION"];
    $arResult["PASSWORD"] = CheckUserPassword($arF);
    $arResult["DOWNLOAD_COUNT"] = $arF['DOWNLOAD_COUNT'];
}
if (!$arF || !empty($_GET['notfoud'])) {
    $arResult["NAME"] = GetMessage("WD_MODULE_IS_FILE_NOT_FOUND");
    $arResult["ICON"] = "nf.png";
    $arResult["F_SIZE"] = 0;
    $arResult["DESCRIPTION"] = GetMessage("WD_MODULE_IS_FILE_NOT_FOUND_DESCRIPTION");
    $arResult["FILE_NOT_FOUND"] = true;
}
if (!empty($_POST['checkViewByGoogle'])) {
    CWebDavTools::sendJsonResponse(array('viewByGoogle' => $arResult["DOWNLOAD_COUNT"] > 0));
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:31,代码来源:component.php

示例9: GetFileName

	public static function GetFileName($path)
	{
		return GetFileName($path);
	}
开发者ID:ASDAFF,项目名称:bxApiDocs,代码行数:4,代码来源:fileman.php

示例10: IsFileUnsafe

function IsFileUnsafe($name)
{
	static $arFiles = false;
	if($arFiles === false)
	{
		$fileList = COption::GetOptionString("main", "~unsafe_files", ".htaccess,.htpasswd,web.config,global.asax");
		$arFiles = explode(",", strtolower($fileList));
	}
	$name = GetFileName($name);
	return in_array(strtolower(TrimUnsafe($name)), $arFiles);
}
开发者ID:nProfessor,项目名称:Mytb,代码行数:11,代码来源:tools.php

示例11: RestoreBackupFile

 /**
  * Восстанавливает базу данных из резервной копии.
  * @param type $BackupFile Имя файла бекапа
  * @param type $Table      Имя таблицы, если нужно восстановить одну таблицу
  */
 public function RestoreBackupFile($BackupFile, $Table = '')
 {
     $zip = new ZipArchive();
     $iferrors = false;
     if (GetSecondFileExt($BackupFile, true) == $this->Name && $zip->open($BackupFile) === true) {
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $filename = $zip->getNameIndex($i);
             if ($Table == '' || $Table == GetFileName($filename, true)) {
                 $sql = $zip->getFromIndex($i);
                 $sql = explode(";", $sql);
                 foreach ($sql as $query) {
                     if (trim($query) == '') {
                         continue;
                     }
                     if (System::database()->MySQLQuery($query) === false) {
                         if (defined('ADMIN_SCRIPT')) {
                             System::admin()->HighlightError(System::database()->MySQLGetErrMsg() . ' (' . $filename . ')');
                         }
                         $iferrors = true;
                     }
                 }
             }
         }
         $zip->close();
         // Обрабытываем ошибки
         if ($iferrors) {
             return 2;
             // Ошибки при восстановлении таблиц
         }
         return 1;
         // Успешно восстановлено
     } else {
         return 3;
         // Неверный формат файла
     }
 }
开发者ID:agnyrussia,项目名称:linkorcms_mod_forms_file_support,代码行数:41,代码来源:mysql.layer.php

示例12: CheckFile

	function CheckFile($arFile, $intMaxSize=0, $strMimeType=false, $strExt=false)
	{
		/****************************** QUOTA ******************************/
		if (COption::GetOptionInt("main", "disk_space") > 0)
		{
			$quota = new CDiskQuota;
			if (!$quota->checkDiskQuota($arFile))
				return $quota->LAST_ERROR;
		}
		/****************************** QUOTA ******************************/
		if(strlen($arFile["name"])<=0)
			return "";

		if(strlen(GetFileName($arFile["name"])) > 255)
			return GetMessage("MAIN_BAD_FILENAME_LEN");

		if(COption::GetOptionString("main", "save_original_file_name", "N")=="Y" && COption::GetOptionString("main", "convert_original_file_name", "Y")!="Y")
		{
			$io = CBXVirtualIo::GetInstance();
			if(!$io->ValidateFilenameString(bx_basename($arFile["name"])))
				return GetMessage("MAIN_BAD_FILENAME1");
		}

		if($intMaxSize>0 && intval($arFile["size"])>$intMaxSize)
		{
			return GetMessage("FILE_BAD_SIZE")." (".CFile::FormatSize($intMaxSize).").";
		}

		$strFileExt = '';
		if($strExt)
		{
			$strFileExt = GetFileExtension($arFile["name"]);
			if($strFileExt == '')
				return GetMessage("FILE_BAD_TYPE");
		}

		//Check mime_type and ext
		if($strMimeType!==false && substr($arFile["type"], 0, strlen($strMimeType)) != $strMimeType)
			return GetMessage("FILE_BAD_TYPE")."!";

		if($strExt===false)
			return "";

		$IsExtCorrect = true;
		if($strExt)
		{
			$IsExtCorrect = false;
			$tok = strtok($strExt,",");
			while($tok)
			{
				if(strtolower(trim($tok)) == strtolower($strFileExt))
				{
					$IsExtCorrect=true;
					break;
				}
				$tok = strtok(",");
			}
		}

		if($IsExtCorrect)
			return "";

		return GetMessage("FILE_BAD_TYPE")." (".strip_tags($strFileExt).")!";
	}
开发者ID:nProfessor,项目名称:Mytb,代码行数:64,代码来源:file.php

示例13: array

    $aTabs[] = array("DIV" => "edit1", "TAB" => GetMessage("FLOW_EDIT_RECORD"), "ICON" => "workflow_edit", "TITLE" => GetMessage("FLOW_NEW_RECORD"));
}
$aTabs[] = array("DIV" => "edit2", "TAB" => GetMessage("FLOW_UPLOADED_FILES"), "ICON" => "workflow_edit", "TITLE" => GetMessage("FLOW_UPLOADED_FILES_TITLE"));
$aTabs[] = array("DIV" => "edit3", "TAB" => GetMessage("FLOW_COMMENTS"), "ICON" => "workflow_edit", "TITLE" => GetMessage("FLOW_COMMENTS_TITLE"));
$tabControl = new CAdminTabControl("tabControl", $aTabs);
// Save or Apply was clicked
if ((strlen($save) > 0 || strlen($apply) > 0) && $WORKFLOW_RIGHT > "R" && $REQUEST_METHOD == "POST" && check_bitrix_sessid()) {
    if (CheckFields()) {
        $nums = intval($nums);
        if ($nums > 0) {
            for ($i = 1; $i <= $nums; $i++) {
                $arFile = $HTTP_POST_FILES["file_" . $i];
                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);
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:31,代码来源:workflow_edit.php

示例14: SaveFile

 function SaveFile($arFile, $strSavePath, $bForceMD5 = false, $bSkipExt = false)
 {
     $strFileName = GetFileName($arFile["name"]);
     /* filename.gif */
     if (isset($arFile["del"]) && $arFile["del"] != '') {
         CFile::DoDelete($arFile["old_file"]);
         if ($strFileName == '') {
             return "NULL";
         }
     }
     if ($arFile["name"] == '') {
         if (isset($arFile["description"]) && intval($arFile["old_file"]) > 0) {
             CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
         }
         return false;
     }
     if (isset($arFile["content"])) {
         if (!isset($arFile["size"])) {
             $arFile["size"] = CUtil::BinStrlen($arFile["content"]);
         }
     } else {
         try {
             $file = new IO\File($arFile["tmp_name"]);
             $arFile["size"] = $file->getSize();
         } catch (IO\IoException $e) {
             $arFile["size"] = 0;
         }
     }
     $arFile["ORIGINAL_NAME"] = $strFileName;
     //translit, replace unsafe chars, etc.
     $strFileName = self::transformName($strFileName, $bForceMD5, $bSkipExt);
     //transformed name must be valid, check disk quota, etc.
     if (self::validateFile($strFileName, $arFile) !== "") {
         return false;
     }
     if ($arFile["type"] == "image/pjpeg" || $arFile["type"] == "image/jpg") {
         $arFile["type"] = "image/jpeg";
     }
     $bExternalStorage = false;
     foreach (GetModuleEvents("main", "OnFileSave", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt))) {
             $bExternalStorage = true;
             break;
         }
     }
     if (!$bExternalStorage) {
         $upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
         $io = CBXVirtualIo::GetInstance();
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             $dir_add = '';
             $i = 0;
             while (true) {
                 $dir_add = substr(md5(uniqid("", true)), 0, 3);
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
                     break;
                 }
                 if ($i >= 25) {
                     $j = 0;
                     while (true) {
                         $dir_add = substr(md5(mt_rand()), 0, 3) . "/" . substr(md5(mt_rand()), 0, 3);
                         if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
                             break;
                         }
                         if ($j >= 25) {
                             $dir_add = substr(md5(mt_rand()), 0, 3) . "/" . md5(mt_rand());
                             break;
                         }
                         $j++;
                     }
                     break;
                 }
                 $i++;
             }
             if (substr($strSavePath, -1, 1) != "/") {
                 $strSavePath .= "/" . $dir_add;
             } else {
                 $strSavePath .= $dir_add . "/";
             }
         } else {
             $strFileExt = $bSkipExt == true || ($ext = GetFileExtension($strFileName)) == '' ? '' : "." . $ext;
             while (true) {
                 if (substr($strSavePath, -1, 1) != "/") {
                     $strSavePath .= "/" . substr($strFileName, 0, 3);
                 } else {
                     $strSavePath .= substr($strFileName, 0, 3) . "/";
                 }
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $strFileName)) {
                     break;
                 }
                 //try the new name
                 $strFileName = md5(uniqid("", true)) . $strFileExt;
             }
         }
         $arFile["SUBDIR"] = $strSavePath;
         $arFile["FILE_NAME"] = $strFileName;
         $strDirName = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/";
         $strDbFileNameX = $strDirName . $strFileName;
         $strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);
         CheckDirPath($strDirName);
         if (is_set($arFile, "content")) {
//.........这里部分代码省略.........
开发者ID:nycmic,项目名称:bittest,代码行数:101,代码来源:file.php

示例15: resize

function resize($thumb, $size = null, $source = "game")
{
    $imageMethod = "GD";
    global $setting;
    switch ($source) {
        case 'download':
            $sourcePath = $setting['sitepath'] . '/ourgames/img/';
            break;
        case 'avatar':
            if (strstr($thumb, 'useruploads')) {
                $sourcePath = $setting['sitepath'] . '/avatars/useruploads/';
            } else {
                $sourcePath = $setting['sitepath'] . '/avatars/';
            }
            break;
        default:
            $sourcePath = $setting['sitepath'] . '/img/';
            break;
    }
    $cachePath = $setting['sitepath'] . '/cache/img/';
    $ext = GetFileExtension($thumb);
    $filename = GetFileName($thumb) . '.' . $ext;
    $thumbPath = $sourcePath . $filename;
    $imagickPath = '/convert/convert';
    if (!file_exists($thumbPath)) {
        return $setting['siteurl'] . 'templates/' . $setting['theme'] . '/skins/' . $setting['skin'] . '/images/nopic150.jpg';
    }
    $newthumbname = md5_file($thumbPath);
    $ext = GetFileExtension($thumbPath);
    if (isset($size['w'])) {
        $w = $size['w'];
    }
    if (isset($size['h'])) {
        $h = $size['h'];
    }
    if (!empty($w) and !empty($h)) {
        $newthumbpath = $cachePath . $newthumbname . '_w' . $w . '_h' . $h . '.' . $ext;
    } elseif (!empty($w)) {
        $newthumbpath = $cachePath . $newthumbname . '_w' . $w . '.' . $ext;
    } elseif (!empty($h)) {
        $newthumbpath = $cachePath . $newthumbname . '_h' . $h . '.' . $ext;
    } else {
        return false;
    }
    if (file_exists($newthumbpath)) {
        return str_replace($setting['sitepath'] . '/', $setting['siteurl'], $newthumbpath);
    }
    switch ($imageMethod) {
        case 'IM':
            list($width, $height) = getimagesize($thumbPath);
            $rw = $width / $w;
            $rh = $height / $h;
            if ($rw > $rh) {
                $nw = round($width / $rh);
                $resize = $nw;
            }
            if ($rh > $rw) {
                $nh = round($height / $rw);
                $resize = "x" . $nh;
            } else {
                $resize = $w . "x" . $h;
            }
            $cmd = $setting['sitepath'] . $imagickPath . " " . $thumbPath . " -resize " . $resize . " -size " . $w . "x" . $h . " xc:transparent +swap -gravity center -composite -quality 90 " . $newthumbpath;
            $c = exec($cmd, $data, $ret);
            if ($ret != 0) {
                return $thumb;
            } else {
                return str_replace($setting['sitepath'] . '/', $setting['siteurl'], $newthumbpath);
            }
            break;
        case 'GD':
            include_once "resizer.php";
            $image = new SimpleImage();
            if (!$image) {
                return $thumbPath;
            }
            $image->load($thumbPath);
            $image->resize($w, $h);
            $image->save($newthumbpath);
            return str_replace($setting['sitepath'] . '/', $setting['siteurl'], $newthumbpath);
            break;
        default:
            return $thumbPath;
            break;
    }
}
开发者ID:royalswe,项目名称:yas26,代码行数:86,代码来源:resize.php


注:本文中的GetFileName函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。