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


PHP SplFileObject::getSize方法代码示例

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


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

示例1: __construct

 /**
  * コンストラクタ
  * 副作用が大量にあるので注意
  */
 public function __construct(ClientInterface $client, $filename = 'stamp.json', $span = 0, $mark_limit = 10000, $back_limit = 3600)
 {
     // ヘッダの送出
     if (!headers_sent()) {
         header('Content-Type: text/html; charset=UTF-8');
     }
     // エラー表示の設定
     error_reporting(-1);
     ini_set('log_errors', PHP_SAPI === 'cli');
     ini_set('display_errors', PHP_SAPI !== 'cli');
     // 重複起動防止
     $file = new \SplFileObject($filename, 'a+b');
     if (!$file->flock(LOCK_EX | LOCK_NB)) {
         throw new \RuntimeException('Failed to lock file.');
     }
     // JSONとして保存してあるデータを取得
     clearstatcache();
     $json = $file->getSize() > 0 ? json_decode($file->fread($file->getSize()), true) : [];
     // JSONに前回実行時刻が保存されていた時
     if (isset($json['prev'])) {
         // 十分に時間が空いたかどうかをチェック
         if (!static::expired($json['prev'], $span)) {
             throw new \RuntimeException('Execution span is not enough.');
         }
     }
     // JSONにマーク済みステータス一覧が記録されていたとき復元する
     if (isset($json['marked'])) {
         $this->marked = array_map('filter_var', (array) $json['marked']);
     }
     $this->client = $client;
     $this->file = $file;
     $this->prev = (new \DateTimeImmutable('now', new \DateTimeZone('UTC')))->format('r');
     $this->mark_limit = $mark_limit;
     $this->back_limit = $back_limit;
 }
开发者ID:mpyw,项目名称:hardbotter,代码行数:39,代码来源:Bot.php

示例2: write

 /**
  * {@inheritdoc}
  */
 public function write(\SplFileObject $file, $text, $newLineAtEnd = false)
 {
     $originalSeek = $file->ftell();
     // Refresh file size
     clearstatcache($file->getFilename());
     if ($file->getSize() - $file->ftell() > 0) {
         $contentAfter = $file->fread($file->getSize() - $file->ftell());
     } else {
         $contentAfter = '';
     }
     $file->fseek($originalSeek);
     $file->fwrite($text . ($newLineAtEnd ? PHP_EOL : ''));
     $file->fwrite($contentAfter);
     return $file;
 }
开发者ID:Babacooll,项目名称:TextFile,代码行数:18,代码来源:PrependingWriter.php

示例3: readComplexRSS

 private function readComplexRSS()
 {
     $filename = $this->createComplexRSS();
     $file = new \SplFileObject($filename, "r");
     $contentToTest = $file->fread($file->getSize());
     $filename = 'tests/RSS/ComplexRSS.rss';
     $file = new \SplFileObject($filename, "r");
     $content = $file->fread($file->getSize());
     return array($contentToTest, $content);
 }
开发者ID:kazuohirai,项目名称:awayfromswag,代码行数:10,代码来源:RSSTest.php

示例4: finalizeFile

 public function finalizeFile(\SplFileObject $fileObject)
 {
     if ($this->headers !== null) {
         // Create tmp file with header
         $fd = fopen('php://temp', 'w+b');
         fputcsv($fd, $this->headers);
         // Copy file content into tmp file
         $fileObject->rewind();
         fwrite($fd, $fileObject->fread($fileObject->getSize()));
         // Overwrite file content with tmp content
         rewind($fd);
         $fileObject->rewind();
         $fileObject->fwrite(stream_get_contents($fd));
         clearstatcache(true, $fileObject->getPathname());
         fclose($fd);
     }
     // Remove last line feed
     $fileObject->ftruncate($fileObject->getSize() - 1);
 }
开发者ID:ThomasArnaud,项目名称:thelia,代码行数:19,代码来源:CSVSerializer.php

示例5: countLines

 /**
  * {@inheritdoc}
  */
 public function countLines(\SplFileObject $file)
 {
     // Refresh file size
     clearstatcache($file->getFilename());
     $previous = $file->key();
     $file->seek($file->getSize());
     $count = $file->key();
     $file->seek($previous);
     return $count;
 }
开发者ID:Babacooll,项目名称:TextFile,代码行数:13,代码来源:SimpleWalker.php

示例6: loadAction

 /**
  * @Route("/download/{filename}/{file}", name="app_download")
  * @Route("/load/{filename}/{file}", name="app_load")
  * @ParamConverter("file", converter="file_converter")
  * @Method("GET")
  * @param string $filename
  * @param \SplFileObject $file
  * @return Response
  */
 public function loadAction($filename, \SplFileObject $file)
 {
     $response = new Response($file->fpassthru());
     $response->headers->set('Content-Type', 'octet/stream');
     $response->headers->set('Content-disposition', 'attachment; filename="' . $filename . '.' . $file->getExtension() . '";"');
     $response->headers->set('Content-Length', $file->getSize());
     $response->headers->set('Cache-Control', 'max-age=31536000, public');
     // 1 year
     $response->sendHeaders();
     return $response->send();
 }
开发者ID:zhooravell,项目名称:box-songs.com,代码行数:20,代码来源:AudioController.php

示例7: addCoverageFromFile

 /**
  * Adds the coverage contained in $coverageFile and deletes the file afterwards
  * @param string $coverageFile Code coverage file
  * @throws \RuntimeException When coverage file is empty
  */
 public function addCoverageFromFile($coverageFile)
 {
     if ($coverageFile === null || !file_exists($coverageFile)) {
         return;
     }
     $file = new \SplFileObject($coverageFile);
     if (0 === $file->getSize()) {
         throw new \RuntimeException("Coverage file {$file->getRealPath()} is empty. This means a PHPUnit process has crashed.");
     }
     $this->addCoverage($this->getCoverageObject($file));
     unlink($file->getRealPath());
 }
开发者ID:brianium,项目名称:paratest,代码行数:17,代码来源:CoverageMerger.php

示例8: readClasses

 /**
  * Read all classes from path
  *
  * @return array $classes
  */
 protected function readClasses()
 {
     $classes = array();
     $directory = new RecursiveDirectoryIterator($this->pathTop, RecursiveDirectoryIterator::SKIP_DOTS);
     $fileIterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);
     foreach ($fileIterator as $file) {
         $fileClass = new SplFileObject($file->getPathname());
         $fileExtension = new SplFileInfo($file->getPathname());
         if ($fileExtension->getExtension() == $this->fileExt) {
             $classes[] = $fileClass->fread($fileClass->getSize());
         }
     }
     return $classes;
 }
开发者ID:gwinn,项目名称:inliner,代码行数:19,代码来源:Inliner.php

示例9: download

 public function download($path)
 {
     if (is_null($path) || empty($path)) {
         throw new InvalidArgumentException('You must specify the item to download.', 400);
     } else {
         if (!$this->exists($path) || !is_file($this->realRootDirectory . DIRECTORY_SEPARATOR . $path)) {
             throw new FileNotFoundException('The specified file does not exist.', 404);
         }
     }
     $fileObject = new \SplFileObject($this->realRootDirectory . DIRECTORY_SEPARATOR . $path);
     HttpResponse::setContentDisposition($fileObject->getBasename());
     HttpResponse::setContentType('application/octet-stream');
     HttpResponse::setHeader('Content-Length', $fileObject->getSize());
     $fileObject->fpassthru();
     exit(0);
 }
开发者ID:chriswells0,项目名称:cwa-lib,代码行数:16,代码来源:FileManager.php

示例10: skipHead

 /**
  * It skips the file headers
  * @return boolean
  * @access private
  * @final
  */
 private final function skipHead()
 {
     if ($this->fileObject->getSize() < 0) {
         return false;
     }
     $this->fileObject->rewind();
     $this->fileObject->fseek(7, SEEK_CUR);
     $mainHead = $this->fileObject->fread(7);
     if (ord($mainHead[2]) != 0x73) {
         return false;
     }
     $headSize = $this->getBytes($mainHead, 5, 2);
     $this->fileObject->fseek($headSize - 7, SEEK_CUR);
     unset($mainHead, $headSize);
     return true;
 }
开发者ID:dmamontov,项目名称:rararchiver,代码行数:22,代码来源:RarArchiver.php

示例11: remove

 /**
  * Removes a Key/Value pair based on its position in the file
  *
  * @param  integer $position The offset position in the file
  */
 public function remove($position)
 {
     $temp = new \SplTempFileObject(-1);
     $this->file->flock(LOCK_EX);
     $filesize = $this->file->getSize();
     $metadata = $this->getMetadata($position);
     // Seek past the document we want to remove
     $this->file->fseek($metadata->length, SEEK_CUR);
     // Write everything after the target document to memory
     $temp->fwrite($this->file->fread($filesize));
     // Clear the file up to the target document
     $this->file->ftruncate($position);
     // Write Temp back to the end of the file
     $temp->fseek(0);
     $this->file->fseek(0, SEEK_END);
     $this->file->fwrite($temp->fread($filesize));
     $this->file->flock(LOCK_UN);
 }
开发者ID:kmfk,项目名称:slowdb,代码行数:23,代码来源:File.php

示例12: _getFile

 /**
  * 获取文件列表
  *
  * @author          mrmsl <msl-138@163.com>
  * @date            2012-07-17 12:46:02
  *
  * @param string $node 节点路径
  *
  * @return array 文件列表
  */
 private function _getFile($node)
 {
     $node = trim($node, '/');
     $this->_denyDirectory($node);
     $file_arr = array();
     $directory = PACKER_JS_PATH . $node . '/';
     $k = 0;
     if (is_dir($directory)) {
         $date_format = sys_config('sys_timezone_datetime_format');
         $d = dir($directory);
         while ($f = $d->read()) {
             if ($f == '.' || $f == '..' || substr($f, 0, 1) == '.') {
                 continue;
             }
             $filename = $directory . '/' . $f;
             if (is_dir($filename)) {
                 $file_arr[$k] = array('text' => $f, 'checked' => $f == 'pack' ? null : false, 'id' => $node . '/' . $f);
                 $file_arr[$k]['data'] = $this->_getFile($f);
                 $k++;
             } elseif (substr($f, -3) == '.js' && !in_array($f, array('app.js'))) {
                 $desc = '';
                 //js文件说明
                 $file = new SplFileObject($filename);
                 if (!strpos($filename, '.min.')) {
                     $file->fgets();
                     $desc = trim(str_replace('*', '', $file->fgets()));
                     //第二行为文件说明
                 }
                 $file_arr[] = array('text' => $f, 'id' => $node . '/' . $f, 'leaf' => true, 'checked' => $node == 'pack' ? null : false, 'filesize' => format_size($file->getSize()), 'filemtime' => new_date($date_format, $file->getMTime()), 'desc' => $desc);
             }
         }
         //end while
         $d->close();
     }
     //end if
     return $file_arr;
 }
开发者ID:yunsite,项目名称:yablog,代码行数:47,代码来源:PackerController.class.php

示例13: updateMetadata

 /**
  * {@inheritdoc}
  */
 public function updateMetadata(MediaInterface $media, $force = true)
 {
     // this is now optimized at all!!!
     $path = tempnam(sys_get_temp_dir(), 'zym_media_update_metadata');
     $fileObject = new \SplFileObject($path, 'w');
     $fileObject->fwrite($this->getReferenceFile($media)->getContent());
     $media->setSize($fileObject->getSize());
 }
开发者ID:geoffreytran,项目名称:zym,代码行数:11,代码来源:FileProvider.php

示例14: updateMetadata

 /**
  * {@inheritdoc}
  */
 public function updateMetadata(MediaInterface $media, $force = true)
 {
     try {
         // this is now optimized at all!!!
         $path = tempnam(sys_get_temp_dir(), 'sonata_update_metadata');
         $fileObject = new \SplFileObject($path, 'w');
         $fileObject->fwrite($this->getReferenceFile($media)->getContent());
         $image = $this->imagineAdapter->open($fileObject->getPathname());
         $size = $image->getSize();
         $media->setSize($fileObject->getSize());
         $media->setWidth($size->getWidth());
         $media->setHeight($size->getHeight());
     } catch (\LogicException $e) {
         $media->setProviderStatus(MediaInterface::STATUS_ERROR);
         $media->setSize(0);
         $media->setWidth(0);
         $media->setHeight(0);
     }
 }
开发者ID:ingeniorweb,项目名称:symfo3cv,代码行数:22,代码来源:ImageProvider.php

示例15: downloadFile

 /**
  * @param  string     $sourceUri
  * @param  string     $destinationUri
  * @param  int        $totalSize
  * @param  string     $hash
  * @throws \Exception
  * @return int
  */
 public function downloadFile($sourceUri, $destinationUri, $totalSize, $hash)
 {
     if (false === ($destination = fopen($destinationUri, 'a+'))) {
         throw new \Exception('Destination is invalid.');
     }
     if (filesize($destinationUri) > 0) {
         throw new \Exception(sprintf("File on destination %s does already exist.", $destinationUri));
     }
     $partFile = $destinationUri . '.part';
     $partFile = new \SplFileObject($partFile, 'a+');
     $size = $partFile->getSize();
     if ($size >= $totalSize) {
         $this->verifyHash($partFile, $hash);
         $this->moveFile($partFile, $destinationUri);
         # close local file
         fclose($destination);
         unset($partFile);
         return 0;
     }
     $range = $size . '-' . $totalSize;
     // Configuration of curl
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RANGE, $range);
     curl_setopt($ch, CURLOPT_URL, $sourceUri);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_NOPROGRESS, FALSE);
     $me = $this;
     curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function ($ch, $dltotal, $dlnow) use($me, $size) {
         if ($dlnow > 0) {
             $this->progress($dltotal, $dlnow, $size + $dlnow);
         }
     });
     $me = $this;
     $isHalted = false;
     $isError = false;
     curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $str) use($me, $partFile, &$isHalted, &$isError) {
         if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 206) {
             $isError = true;
             return -1;
         }
         $partFile->fwrite($str);
         if ($me->shouldHalt()) {
             $isHalted = true;
             return -1;
         }
         return strlen($str);
     });
     $result = curl_exec($ch);
     $error = curl_error($ch);
     curl_close($ch);
     if ($isError && !$isHalted) {
         throw new \Exception("Wrong http code");
     }
     if ($result === false && !$isHalted) {
         throw new \Exception($error);
     }
     clearstatcache(false, $partFile->getPathname());
     $size = $partFile->getSize();
     if ($size >= $totalSize) {
         $this->verifyHash($partFile, $hash);
         $this->moveFile($partFile, $destinationUri);
     }
     // close local file
     fclose($destination);
     unset($partFile);
     return $size;
 }
开发者ID:ClaudioThomas,项目名称:shopware-4,代码行数:78,代码来源:Download.php


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