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


PHP File::readable方法代码示例

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


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

示例1: get

 /**
  * @param $path
  * @return mixed
  */
 protected function get($path)
 {
     $file = new File($path);
     if (!$file->readable()) {
         if (true === $this->throws) {
             throw new \RuntimeException('not readable ' . $path);
         }
         return false;
     }
     $serialize = $file->read();
     $ret = unserialize($serialize);
     if (empty($ret)) {
         if (true === $this->throws) {
             throw new \UnexpectedValueException('empty data');
         }
         return false;
     }
     return $ret;
 }
开发者ID:Rmtram,项目名称:TextDatabase,代码行数:23,代码来源:Reader.php

示例2: file

 /**
  * Setup for display or download the given file.
  *
  * If $_SERVER['HTTP_RANGE'] is set a slice of the file will be
  * returned instead of the entire file.
  *
  * ### Options keys
  *
  * - name: Alternate download name
  * - download: If `true` sets download header and forces file to be downloaded rather than displayed in browser
  *
  * @param string $path Path to file. If the path is not an absolute path that resolves
  *   to a file, `APP` will be prepended to the path.
  * @param array $options Options See above.
  * @return void
  * @throws \Cake\Network\Exception\NotFoundException
  */
 public function file($path, array $options = [])
 {
     $options += ['name' => null, 'download' => null];
     if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) {
         throw new NotFoundException('The requested file contains `..` and will not be read.');
     }
     if (!is_file($path)) {
         $path = APP . $path;
     }
     $file = new File($path);
     if (!$file->exists() || !$file->readable()) {
         if (Configure::read('debug')) {
             throw new NotFoundException(sprintf('The requested file %s was not found or not readable', $path));
         }
         throw new NotFoundException(__d('cake', 'The requested file was not found'));
     }
     $extension = strtolower($file->ext());
     $download = $options['download'];
     if ((!$extension || $this->type($extension) === false) && $download === null) {
         $download = true;
     }
     $fileSize = $file->size();
     if ($download) {
         $agent = env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
             $contentType = 'application/octet-stream';
         } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/force-download';
         }
         if (!empty($contentType)) {
             $this->type($contentType);
         }
         if ($options['name'] === null) {
             $name = $file->name;
         } else {
             $name = $options['name'];
         }
         $this->download($name);
         $this->header('Content-Transfer-Encoding', 'binary');
     }
     $this->header('Accept-Ranges', 'bytes');
     $httpRange = env('HTTP_RANGE');
     if (isset($httpRange)) {
         $this->_fileRange($file, $httpRange);
     } else {
         $this->header('Content-Length', $fileSize);
     }
     $this->_clearBuffer();
     $this->_file = $file;
 }
开发者ID:rabinpal,项目名称:cakephp,代码行数:67,代码来源:Response.php

示例3: testReadable

 /**
  * testReadable method
  *
  * @return void
  */
 public function testReadable()
 {
     $someFile = new File(TMP . 'some_file.txt', false);
     $this->assertTrue($someFile->open());
     $this->assertTrue($someFile->readable());
     $someFile->close();
     $someFile->delete();
 }
开发者ID:Slayug,项目名称:castor,代码行数:13,代码来源:FileTest.php


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