當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::open方法代碼示例

本文整理匯總了PHP中Bitrix\Main\IO\File::open方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::open方法的具體用法?PHP File::open怎麽用?PHP File::open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bitrix\Main\IO\File的用法示例。


在下文中一共展示了File::open方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isCacheExpired

 public function isCacheExpired($path)
 {
     $file = new IO\File($path);
     if (!$file->isExists()) {
         return true;
     }
     if (!$file instanceof IO\IFileStream) {
         return true;
     }
     $dfile = $file->open("r");
     $str_tmp = fread($dfile, 150);
     fclose($dfile);
     if (preg_match("/dateexpire\\s*=\\s*'([\\d]+)'/im", $str_tmp, $arTmp) || preg_match("/^BX\\d{12}(\\d{12})/", $str_tmp, $arTmp) || preg_match("/^(\\d{12})/", $str_tmp, $arTmp)) {
         if (strlen($arTmp[1]) <= 0 || doubleval($arTmp[1]) < mktime()) {
             return true;
         }
     }
     return false;
 }
開發者ID:,項目名稱:,代碼行數:19,代碼來源:

示例2: download

 /**
  * Downloads and saves a file.
  *
  * @param string $url URI to download
  * @param string $filePath Absolute file path
  * @return bool
  */
 public function download($url, $filePath)
 {
     $dir = IO\Path::getDirectory($filePath);
     IO\Directory::createDirectory($dir);
     $file = new IO\File($filePath);
     $handler = $file->open("w+");
     if ($handler !== false) {
         $this->setOutputStream($handler);
         $res = $this->query(self::HTTP_GET, $url);
         fclose($handler);
         return $res;
     }
     return false;
 }
開發者ID:mrdeadmouse,項目名稱:u136006,代碼行數:21,代碼來源:httpclient.php

示例3: ViewByUser

 static function ViewByUser($arFile, $arOptions = array())
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     $fastDownload = COption::GetOptionString('main', 'bx_fast_download', 'N') == 'Y';
     $attachment_name = "";
     $content_type = "";
     $specialchars = false;
     $force_download = false;
     $cache_time = 10800;
     $fromClouds = false;
     if (is_array($arOptions)) {
         if (isset($arOptions["content_type"])) {
             $content_type = $arOptions["content_type"];
         }
         if (isset($arOptions["specialchars"])) {
             $specialchars = $arOptions["specialchars"];
         }
         if (isset($arOptions["force_download"])) {
             $force_download = $arOptions["force_download"];
         }
         if (isset($arOptions["cache_time"])) {
             $cache_time = intval($arOptions["cache_time"]);
         }
         if (isset($arOptions["attachment_name"])) {
             $attachment_name = $arOptions["attachment_name"];
         }
     }
     if ($cache_time < 0) {
         $cache_time = 0;
     }
     if (is_array($arFile)) {
         if (isset($arFile["SRC"])) {
             $filename = $arFile["SRC"];
         } elseif (isset($arFile["tmp_name"])) {
             $filename = "/" . ltrim(substr($arFile["tmp_name"], strlen($_SERVER["DOCUMENT_ROOT"])), "/");
         } else {
             $filename = static::GetFileSRC($arFile);
         }
     } else {
         if ($arFile = static::GetFileArray($arFile)) {
             $filename = $arFile["SRC"];
         } else {
             $filename = '';
         }
     }
     if ($filename == '') {
         return false;
     }
     if ($content_type == '' && isset($arFile["CONTENT_TYPE"])) {
         $content_type = $arFile["CONTENT_TYPE"];
     }
     //we produce resized jpg for original bmp
     if ($content_type == '' || $content_type == "image/bmp") {
         if (isset($arFile["tmp_name"])) {
             $content_type = static::GetContentType($arFile["tmp_name"], true);
         } else {
             $content_type = static::GetContentType($_SERVER["DOCUMENT_ROOT"] . $filename);
         }
     }
     if ($arFile["ORIGINAL_NAME"] != '') {
         $name = $arFile["ORIGINAL_NAME"];
     } elseif ($arFile["name"] != '') {
         $name = $arFile["name"];
     } else {
         $name = $arFile["FILE_NAME"];
     }
     if (isset($arFile["EXTENSION_SUFFIX"]) && $arFile["EXTENSION_SUFFIX"] != '') {
         $name = substr($name, 0, -strlen($arFile["EXTENSION_SUFFIX"]));
     }
     $name = str_replace(array("\n", "\r"), '', $name);
     if ($attachment_name) {
         $attachment_name = str_replace(array("\n", "\r"), '', $attachment_name);
     } else {
         $attachment_name = $name;
     }
     if (!$force_download) {
         if (!static::IsImage($name, $content_type) || $arFile["HEIGHT"] <= 0 || $arFile["WIDTH"] <= 0) {
             //only valid images can be downloaded inline
             $force_download = true;
         }
     }
     $content_type = static::NormalizeContentType($content_type);
     if ($force_download) {
         $specialchars = false;
     }
     $src = null;
     $file = new IO\File($_SERVER["DOCUMENT_ROOT"] . $filename);
     if (substr($filename, 0, 1) == "/") {
         try {
             $src = $file->open(IO\FileStreamOpenMode::READ);
         } catch (IO\IoException $e) {
             return false;
         }
     } else {
         if (!$fastDownload) {
             $src = new \Bitrix\Main\Web\HttpClient();
         } elseif (intval($arFile['HANDLER_ID']) > 0) {
             $fromClouds = true;
         }
//.........這裏部分代碼省略.........
開發者ID:nycmic,項目名稱:bittest,代碼行數:101,代碼來源:file.php


注:本文中的Bitrix\Main\IO\File::open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。