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


PHP CFile::DoDelete方法代码示例

本文整理汇总了PHP中CFile::DoDelete方法的典型用法代码示例。如果您正苦于以下问题:PHP CFile::DoDelete方法的具体用法?PHP CFile::DoDelete怎么用?PHP CFile::DoDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFile的用法示例。


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

示例1: testSaveToBXFileAfterGetContent

 public function testSaveToBXFileAfterGetContent()
 {
     $Request = new RequestBXFile(self::$_urlTestFiles . '/favicon.png');
     $Request->send();
     $this->assertEquals('PNG', substr($Request->getBody(), 1, 3));
     $fileID = $Request->saveToBXFile('/upload//obx.core/test/RequestBXFile');
     $this->assertTrue($fileID > 0);
     $arFile = \CFile::GetFileArray($fileID);
     $this->assertEquals('favicon.png', $arFile['ORIGINAL_NAME']);
     $this->assertEquals('image/png', $arFile['CONTENT_TYPE']);
     $this->assertFileExists(self::$_docRoot . '/upload/' . $arFile['SUBDIR'] . '/' . $arFile['FILE_NAME']);
     \CFile::DoDelete($arFile['ID']);
     $this->assertFileNotExists(self::$_docRoot . '/upload/' . $arFile['SUBDIR'] . '/' . $arFile['FILE_NAME']);
 }
开发者ID:OpenBX,项目名称:obx.core,代码行数:14,代码来源:RequestBXFile.php

示例2: 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 (array_key_exists("content", $arFile)) {
         if (!array_key_exists("size", $arFile)) {
             $arFile["size"] = CUtil::BinStrlen($arFile["content"]);
         }
     } else {
         $arFile["size"] = filesize($arFile["tmp_name"]);
     }
     $arFile["ORIGINAL_NAME"] = $strFileName;
     $io = CBXVirtualIo::GetInstance();
     if (self::validateFile($strFileName, $arFile, $bForceMD5) !== "") {
         return false;
     }
     $upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
     if ($arFile["type"] == "image/pjpeg" || $arFile["type"] == "image/jpg") {
         $arFile["type"] = "image/jpeg";
     }
     //.jpe is not image type on many systems
     if (strtolower(GetFileExtension($strFileName)) == "jpe") {
         $strFileName = substr($strFileName, 0, -4) . ".jpg";
     }
     $bExternalStorage = false;
     foreach (GetModuleEvents("main", "OnFileSave", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt))) {
             $bExternalStorage = true;
             break;
         }
     }
     if (!$bExternalStorage) {
         $newName = '';
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             $dir_add = '';
             $i = 0;
             while (true) {
                 $dir_add = substr(md5(uniqid(mt_rand(), 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 . "/";
             }
             $newName = $strFileName;
         } else {
             $strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, ".");
             while (true) {
                 $newName = md5(uniqid(mt_rand(), true)) . $strFileExt;
                 if (substr($strSavePath, -1, 1) != "/") {
                     $strSavePath .= "/" . substr($newName, 0, 3);
                 } else {
                     $strSavePath .= substr($newName, 0, 3) . "/";
                 }
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $newName)) {
                     break;
                 }
             }
         }
         $arFile["SUBDIR"] = $strSavePath;
         $arFile["FILE_NAME"] = $newName;
         $strDirName = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/";
         $strDbFileNameX = $strDirName . $newName;
         $strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);
         CheckDirPath($strDirName);
         if (is_set($arFile, "content")) {
             $f = fopen($strPhysicalFileNameX, "ab");
             if (!$f) {
                 return false;
//.........这里部分代码省略.........
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:101,代码来源:file.php

示例3: OnFileSave


//.........这里部分代码省略.........
         return false;
     }
     $copySize = false;
     $subDir = "";
     $filePath = "";
     if (array_key_exists("content", $arFile)) {
         $arFile["tmp_name"] = CTempFile::GetFileName($arFile["name"]);
         CheckDirPath($arFile["tmp_name"]);
         $fp = fopen($arFile["tmp_name"], "ab");
         if ($fp) {
             fwrite($fp, $arFile["content"]);
             fclose($fp);
         }
     }
     if (array_key_exists("bucket", $arFile)) {
         $newName = bx_basename($arFile["tmp_name"]);
         $prefix = $bucket->GetFileSRC("/");
         $subDir = substr($arFile["tmp_name"], strlen($prefix));
         $subDir = substr($subDir, 0, -strlen($newName) - 1);
     } else {
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             if (COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y") {
                 $newName = CCloudStorage::translit($strFileName);
             } else {
                 $newName = $strFileName;
             }
         } else {
             $strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, ".");
             $newName = md5(uniqid(mt_rand(), true)) . $strFileExt;
         }
         //check for double extension vulnerability
         $newName = RemoveScriptExtension($newName);
         while (true) {
             $strRand = md5(mt_rand());
             $strRand = substr($strRand, 0, 3) . "/" . $strRand;
             if (substr($strSavePath, -1) == "/") {
                 $subDir = $strSavePath . $strRand;
             } else {
                 $subDir = $strSavePath . "/" . $strRand;
             }
             $subDir = ltrim($subDir, "/");
             $filePath = "/" . $subDir . "/" . $newName;
             if (!$bucket->FileExists($filePath)) {
                 break;
             }
         }
         $targetPath = $bucket->GetFileSRC("/");
         if (strpos($arFile["tmp_name"], $targetPath) === 0) {
             $arDbFile = array("SUBDIR" => "", "FILE_NAME" => substr($arFile["tmp_name"], strlen($targetPath)), "CONTENT_TYPE" => $arFile["type"]);
             $copyPath = $bucket->FileCopy($arDbFile, $filePath);
             if (!$copyPath) {
                 return false;
             }
             $copySize = $bucket->GetFileSize("/" . urldecode(substr($copyPath, strlen($targetPath))));
         } else {
             $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, false);
             if (is_array($imgArray) && $imgArray[2] == IMAGETYPE_JPEG) {
                 $exifData = CFile::ExtractImageExif($arFile["tmp_name"]);
                 if ($exifData && isset($exifData['Orientation'])) {
                     $properlyOriented = CFile::ImageHandleOrientation($exifData['Orientation'], $arFile["tmp_name"]);
                     if ($properlyOriented) {
                         $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95'));
                         if ($jpgQuality <= 0 || $jpgQuality > 100) {
                             $jpgQuality = 95;
                         }
                         imagejpeg($properlyOriented, $arFile["tmp_name"], $jpgQuality);
                     }
                 }
             }
             if (!$bucket->SaveFile($filePath, $arFile)) {
                 return false;
             }
         }
     }
     $arFile["HANDLER_ID"] = $bucket->ID;
     $arFile["SUBDIR"] = $subDir;
     $arFile["FILE_NAME"] = $newName;
     $arFile["WIDTH"] = 0;
     $arFile["HEIGHT"] = 0;
     if (array_key_exists("bucket", $arFile)) {
         $arFile["WIDTH"] = $arFile["width"];
         $arFile["HEIGHT"] = $arFile["height"];
         $arFile["size"] = $arFile["file_size"];
     } elseif ($copySize !== false) {
         $arFile["size"] = $copySize;
         $bucket->IncFileCounter($copySize);
     } else {
         $bucket->IncFileCounter(filesize($arFile["tmp_name"]));
         $flashEnabled = !CFile::IsImage($arFile["ORIGINAL_NAME"], $arFile["type"]);
         $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, $flashEnabled);
         if (is_array($imgArray)) {
             $arFile["WIDTH"] = $imgArray[0];
             $arFile["HEIGHT"] = $imgArray[1];
         }
     }
     if (isset($arFile["old_file"])) {
         CFile::DoDelete($arFile["old_file"]);
     }
     return true;
 }
开发者ID:rasuldev,项目名称:torino,代码行数:101,代码来源:storage.php

示例4: OnFileSave


//.........这里部分代码省略.........
			return false;

		if(array_key_exists("bucket", $arFile))
		{
			$newName = bx_basename($arFile["tmp_name"]);

			$prefix = $bucket->GetFileSRC("/");
			$subDir = substr($arFile["tmp_name"], strlen($prefix));
			$subDir = substr($subDir, 0, -strlen($newName)-1);
		}
		else
		{
			if(
				$bForceMD5 != true
				&& COption::GetOptionString("main", "save_original_file_name", "N")=="Y"
			)
			{
				if(COption::GetOptionString("main", "convert_original_file_name", "Y")=="Y")
					$newName = CCloudStorage::translit($strFileName);
				else
					$newName = $strFileName;
			}
			else
			{
				$strFileExt = ($bSkipExt == true? '' : strrchr($strFileName, "."));
				$newName = md5(uniqid(mt_rand(), true)).$strFileExt;
			}

			//check for double extension vulnerability
			$newName = RemoveScriptExtension($newName);

			while(true)
			{
				$strRand = md5(mt_rand());
				$strRand = substr($strRand, 0, 3)."/".$strRand;

				if(substr($strSavePath, -1) == "/")
					$subDir = $strSavePath.$strRand;
				else
					$subDir = $strSavePath."/".$strRand;
				$subDir = ltrim($subDir, "/");

				$filePath = "/".$subDir."/".$newName;

				if(!$bucket->FileExists($filePath))
					break;
			}

			if(!$bucket->SaveFile($filePath, $arFile))
				return false;
		}

		$arFile["HANDLER_ID"] = $bucket->ID;
		$arFile["SUBDIR"] = $subDir;
		$arFile["FILE_NAME"] = $newName;

		$arFile["WIDTH"] = 0;
		$arFile["HEIGHT"] = 0;
		if(array_key_exists("bucket", $arFile))
		{
			$arFile["WIDTH"] = $arFile["width"];
			$arFile["HEIGHT"] = $arFile["height"];
			$arFile["size"] = $arFile["file_size"];
		}
		elseif(array_key_exists("content", $arFile))
		{
			$tmp_name = tempnam();
			$fp = fopen($tmp_name, "ab");
			if($fp)
			{
				if(fwrite($fp, $arFile["content"]))
				{
					$bucket->IncFileCounter(filesize($tmp_name));
					$imgArray = CFile::GetImageSize($tmp_name);
					if(is_array($imgArray))
					{
						$arFile["WIDTH"] = $imgArray[0];
						$arFile["HEIGHT"] = $imgArray[1];
					}
				}
				fclose($fp);
				unlink($tmp_name);
			}
		}
		else
		{
			$bucket->IncFileCounter(filesize($arFile["tmp_name"]));
			$imgArray = CFile::GetImageSize($arFile["tmp_name"]);
			if(is_array($imgArray))
			{
				$arFile["WIDTH"] = $imgArray[0];
				$arFile["HEIGHT"] = $imgArray[1];
			}
		}

		if(isset($arFile["old_file"]))
			CFile::DoDelete($arFile["old_file"]);

		return true;
	}
开发者ID:nProfessor,项目名称:Mytb,代码行数:101,代码来源:storage.php

示例5: 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(is_set($arFile, "description") && intval($arFile["old_file"])>0)
				CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
			return false;
		}

		if(is_set($arFile, "content") && !is_set($arFile, "size"))
			$arFile["size"] = CUtil::BinStrlen($arFile["content"]);
		else
			$arFile["size"] = filesize($arFile["tmp_name"]);

		/****************************** QUOTA ******************************/
		if (COption::GetOptionInt("main", "disk_space") > 0)
		{
			$quota = new CDiskQuota();
			if (!$quota->checkDiskQuota($arFile))
				return false;
		}
		/****************************** QUOTA ******************************/

		$arFile["ORIGINAL_NAME"] = $strFileName;

		$io = CBXVirtualIo::GetInstance();
		if($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y")
		{
			if(COption::GetOptionString("main", "translit_original_file_name", "N") == "Y")
				$strFileName = CUtil::translit($strFileName, LANGUAGE_ID, array("max_len"=>1024, "safe_chars"=>"."));

			if(COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y")
				$strFileName = $io->RandomizeInvalidFilename($strFileName);
		}

		if(!$io->ValidateFilenameString($strFileName))
			return false;

		//check for double extension vulnerability
		$strFileName = RemoveScriptExtension($strFileName);
		if($strFileName == '')
			return false;

		if(strlen($strFileName) > 255)
			return false;

		//check .htaccess etc.
		if(IsFileUnsafe($strFileName))
			return false;

		//nginx returns octet-stream for .jpg
		if(GetFileNameWithoutExtension($strFileName) == '')
			return false;

		$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");

		if($arFile["type"]=="image/pjpeg" || $arFile["type"]=="image/jpg")
			$arFile["type"]="image/jpeg";

		//.jpe is not image type on many systems
		if(strtolower(GetFileExtension($strFileName)) == "jpe")
			$strFileName = substr($strFileName, 0, -4).".jpg";

		$bExternalStorage = false;
		foreach(GetModuleEvents("main", "OnFileSave", true) as $arEvent)
		{
			if(ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt)))
			{
				$bExternalStorage = true;
				break;
			}
		}

		if(!$bExternalStorage)
		{
			$newName = '';
			if($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N")=="Y")
			{
				$dir_add = '';
				$i=0;
				while(true)
				{
					$dir_add = substr(md5(uniqid(mt_rand(), 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);
//.........这里部分代码省略.........
开发者ID:nProfessor,项目名称:Mytb,代码行数:101,代码来源:file.php

示例6: 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


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