当前位置: 首页>>代码示例>>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;未经允许,请勿转载。