コード例 #1
0
 /**
  * Fetches the next item from the stream using defined behavior
  * 
  * @param resource $stream_handle The stream handle that is being use in the current context
  *
  * @access public
  *
  * @return string A single character or null if FEOF
  */
 public function next($stream_handle)
 {
     //If feof, end it
     if (feof($stream_handle)) {
         return null;
     }
     //Extract the character
     $c = ($c = fgetc($stream_handle)) === false ? null : $c;
     //If character is 195 (utf8 control character)
     if ($c !== null && ord($c) == 195) {
         $c .= fgetc($stream_handle);
     }
     //If character is 195 (utf8 control character)
     if ($c !== null && ord($c) == 239) {
         //Get the next two characters and seek back if not UTF8 bom
         $c2 = fgetc($stream_handle);
         $c3 = fgetc($stream_handle);
         if (ord($c2) == 187 && ord($c3) == 191) {
             //Ok, BOM skipped, read next char using defined next method (to support possible UTF-8 chars)
             $c = $this->next($stream_handle);
         } else {
             //Seek back 2 characters, it was not a UTF-8 BOM
             fseek($stream_handle, ftell($stream_handle) - 2);
         }
     }
     //Return it
     return $c;
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filename = $input->getArgument('filename');
     if (!$filename) {
         if (0 !== ftell(STDIN)) {
             throw new \RuntimeException('Please provide a filename or pipe file content to STDIN.');
         }
         $content = '';
         while (!feof(STDIN)) {
             $content .= fread(STDIN, 1024);
         }
         return $this->display($input, $output, array($this->validate($content)));
     }
     if (0 !== strpos($filename, '@') && !is_readable($filename)) {
         throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
     }
     $files = array();
     if (is_file($filename)) {
         $files = array($filename);
     } elseif (is_dir($filename)) {
         $files = Finder::create()->files()->in($filename)->name('*.yml');
     } else {
         $dir = $this->getApplication()->getKernel()->locateResource($filename);
         $files = Finder::create()->files()->in($dir)->name('*.yml');
     }
     $filesInfo = array();
     foreach ($files as $file) {
         $filesInfo[] = $this->validate(file_get_contents($file), $file);
     }
     return $this->display($input, $output, $filesInfo);
 }
コード例 #3
0
 /**
  * Get value for a named parameter.
  *
  * @param mixed $parameter Parameter to get a value for
  * @param array $argv Argument values passed to the script when run in console.
  * @return mixed
  */
 public function getValueForParameter($parameter, $argv = array())
 {
     // Default value
     $parameterValue = null;
     // Check STDIN for data
     if (ftell(STDIN) !== false) {
         // Read from STDIN
         $fs = fopen("php://stdin", "r");
         if ($fs !== false) {
             /*
             				while (!feof($fs)) {
             					$data = fread($fs, 1);
             					var_dump($data);
             					$parameterValue .= $data;
             				} */
             $parameterValue = stream_get_contents($fs);
             fclose($fs);
         }
         // Remove ending \r\n
         $parameterValue = rtrim($parameterValue);
         if (strtolower($parameterValue) == 'true') {
             $parameterValue = true;
         } else {
             if (strtolower($parameterValue) == 'false') {
                 $parameterValue = false;
             }
         }
     }
     // Done!
     return $parameterValue;
 }
コード例 #4
0
ファイル: Stream.php プロジェクト: guide42/ochenta
 function tell() : int
 {
     if (!is_resource($this->resource) || ($pos = ftell($this->resource)) === FALSE) {
         throw new \RuntimeException('Could not tell the position');
     }
     return $pos;
 }
コード例 #5
0
ファイル: common.php プロジェクト: neel/bong
function _fstrpos($resource, $str, $direction = 1)
{
    $pos = ftell($resource);
    $buff = fgets($resource);
    fseek($resource, $pos);
    return $pos + ($direction == 1 ? strpos($buff, $str) : strrpos($buff, $str));
}
コード例 #6
0
ファイル: Upyun.class.php プロジェクト: RqHe/aunet1
  */
 public function mkdir($savepath)
 {
     return true;
 }
 /**
  * 保存指定文件
  * @param  array   $file    保存的文件信息
  * @param  boolean $replace 同名文件是否覆盖
  * @return boolean          保存状态,true-成功,false-失败
  */
 public function save($file, $replace = true)
 {
     $header['Content-Type'] = $file['type'];
     $header['Content-MD5'] = $file['md5'];
     $header['Mkdir'] = 'true';
     $resource = fopen($file['tmp_name'], 'r');
     $save = $this->rootPath . $file['savepath'] . $file['savename'];
     $data = $this->request($save, 'PUT', $header, $resource);
     return false === $data ? false : true;
 }
 /**
  * 获取最后一次上传错误信息
  * @return string 错误信息
  */
 public function getError()
 {
     return $this->error;
 }
 /**
  * 请求又拍云服务器
  * @param  string   $path    请求的PATH
  * @param  string   $method  请求方法
  * @param  array    $headers 请求header
  * @param  resource $body    上传文件资源
  * @return boolean
  */
 private function request($path, $method, $headers = null, $body = null)
 {
     $uri = "/{$this->config['bucket']}/{$path}";
     $ch = curl_init($this->config['host'] . $uri);
     $_headers = array('Expect:');
     if (!is_null($headers) && is_array($headers)) {
         foreach ($headers as $k => $v) {
             array_push($_headers, "{$k}: {$v}");
         }
     }
     $length = 0;
     $date = gmdate('D, d M Y H:i:s \\G\\M\\T');
     if (!is_null($body)) {
         if (is_resource($body)) {
             fseek($body, 0, SEEK_END);
             $length = ftell($body);
             fseek($body, 0);
             array_push($_headers, "Content-Length: {$length}");
             curl_setopt($ch, CURLOPT_INFILE, $body);
             curl_setopt($ch, CURLOPT_INFILESIZE, $length);
         } else {
             $length = @strlen($body);
             array_push($_headers, "Content-Length: {$length}");
             curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
コード例 #7
0
ファイル: YamlLintCommand.php プロジェクト: Dren-x/mobit
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (false !== strpos($input->getFirstArgument(), ':l')) {
         $output->writeln('<comment>The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.</comment>');
     }
     $filename = $input->getArgument('filename');
     if (!$filename) {
         if (0 !== ftell(STDIN)) {
             throw new \RuntimeException('Please provide a filename or pipe file content to STDIN.');
         }
         $content = '';
         while (!feof(STDIN)) {
             $content .= fread(STDIN, 1024);
         }
         return $this->display($input, $output, array($this->validate($content)));
     }
     if (0 !== strpos($filename, '@') && !is_readable($filename)) {
         throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
     }
     $files = array();
     if (is_file($filename)) {
         $files = array($filename);
     } elseif (is_dir($filename)) {
         $files = Finder::create()->files()->in($filename)->name('*.yml');
     } else {
         $dir = $this->getApplication()->getKernel()->locateResource($filename);
         $files = Finder::create()->files()->in($dir)->name('*.yml');
     }
     $filesInfo = array();
     foreach ($files as $file) {
         $filesInfo[] = $this->validate(file_get_contents($file), $file);
     }
     return $this->display($input, $output, $filesInfo);
 }
コード例 #8
0
 /**
  * Returns file size by seeking at the end of file
  * @see http://www.php.net/manual/en/function.filesize.php#79023
  * @see http://www.php.net/manual/en/function.filesize.php#102135
  * @param string $path Full path to file
  * @return BigInteger
  * @throws Exception
  */
 public function getFileSize($path)
 {
     // This should work for large files on 64bit platforms and for small files everywhere
     $fp = fopen($path, "rb");
     if (!$fp) {
         throw new Exception("Cannot open specified file for reading.");
     }
     $flockResult = flock($fp, LOCK_SH);
     $seekResult = fseek($fp, 0, SEEK_END);
     $position = ftell($fp);
     flock($fp, LOCK_UN);
     fclose($fp);
     // TODO: There is *hope* that ftell() or fseek() fails when file is over 4GB
     // TODO: This really needs tests, any ideas how to test this in CI? (please let me know)
     if ($flockResult === false) {
         throw new Exception("Couldn't get file lock. Operation abandoned.");
     }
     if ($seekResult !== 0) {
         throw new Exception("Seeking to end of file failed");
     }
     if ($position === false) {
         throw new Exception("Cannot determine position in file. ftell() failed.");
     }
     // PHP uses internally (in C) UNSIGNED integer for file size.
     // PHP uses signed implicitly
     // convert signed (max val +2^31) -> unsigned integer will extend range for 32-bit to (+2^32)
     return BigInteger::of(sprintf("%u", $position));
 }
コード例 #9
0
ファイル: Lint.php プロジェクト: winglian/twigbridge
 /**
  * {@inheritdoc}
  */
 public function fire()
 {
     $this->twig = $this->laravel['twig'];
     $format = $this->option('format');
     // Check STDIN for the template
     if (ftell(STDIN) === 0) {
         // Read template in
         $template = '';
         while (!feof(STDIN)) {
             $template .= fread(STDIN, 1024);
         }
         return $this->display([$this->validate($template)], $format);
     }
     $files = $this->getFiles($this->argument('filename'), $this->option('file'), $this->option('directory'));
     $details = [];
     foreach ($files as $file) {
         try {
             $template = $this->getContents($file);
         } catch (Twig_Error_Loader $e) {
             throw new RuntimeException(sprintf('File or directory "%s" is not readable', $file));
         }
         $details[] = $this->validate($template, $file);
     }
     return $this->display($details, $format);
 }
コード例 #10
0
ファイル: knx-function.php プロジェクト: stawen/domovision
function tail($file, &$pos)
{
    // get the size of the file
    if (!$pos) {
        $pos = filesize($file);
    }
    // Open an inotify instance
    $fd = inotify_init();
    // Watch $file for changes.
    $watch_descriptor = inotify_add_watch($fd, $file, IN_ALL_EVENTS);
    // Loop forever (breaks are below)
    while (true) {
        // Read events (inotify_read is blocking!)
        $events = inotify_read($fd);
        // Loop though the events which occured
        foreach ($events as $event => $evdetails) {
            // React on the event type
            switch (true) {
                // File was modified
                case $evdetails['mask'] & IN_MODIFY:
                    // Stop watching $file for changes
                    inotify_rm_watch($fd, $watch_descriptor);
                    // Close the inotify instance
                    fclose($fd);
                    // open the file
                    $fp = fopen($file, 'r');
                    if (!$fp) {
                        return false;
                    }
                    // seek to the last EOF position
                    fseek($fp, $pos);
                    // read until EOF
                    while (!feof($fp)) {
                        $buf .= fread($fp, 8192);
                    }
                    // save the new EOF to $pos
                    $pos = ftell($fp);
                    // (remember: $pos is called by reference)
                    // close the file pointer
                    fclose($fp);
                    // return the new data and leave the function
                    return $buf;
                    break;
                    // File was moved or deleted
                // File was moved or deleted
                case $evdetails['mask'] & IN_MOVE:
                case $evdetails['mask'] & IN_MOVE_SELF:
                case $evdetails['mask'] & IN_DELETE:
                case $evdetails['mask'] & IN_DELETE_SELF:
                    // Stop watching $file for changes
                    inotify_rm_watch($fd, $watch_descriptor);
                    // Close the inotify instance
                    fclose($fd);
                    // Return a failure
                    return false;
                    break;
            }
        }
    }
}
コード例 #11
0
ファイル: File.php プロジェクト: itephp/framework
 /**
  * @param Request $request
  * @param Response $response
  */
 public function render(Request $request, Response $response)
 {
     if (!$this->environment->isSilent()) {
         header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage());
         foreach ($response->getHeaders() as $name => $value) {
             header($name . ': ' . $value);
         }
     }
     if ($response->getStatusCode() < 299) {
         $startRange = 0;
         $endRange = filesize($response->getContent()) - 1;
         try {
             $contentRange = $response->getHeader('Content-Range');
             if (preg_match('/^bytes ([0-9]+)-([0-9]+)\\/([0-9]+)$/', $contentRange, $match)) {
                 $startRange = (int) $match[1];
                 $endRange = (int) $match[2];
             }
         } catch (HeaderNotFoundException $e) {
             //skipp
         }
         $buffer = 1024 * 8;
         $file = @fopen($response->getContent(), 'rb');
         fseek($file, $startRange);
         while (!feof($file) && ($p = ftell($file)) <= $endRange) {
             if ($p + $buffer > $endRange) {
                 $buffer = $endRange - $p + 1;
             }
             set_time_limit(0);
             echo fread($file, $buffer);
             flush();
         }
         fclose($file);
     }
 }
コード例 #12
0
 function stream_tell()
 {
     if (!empty($this->stream)) {
         return ftell($this->stream);
     }
     return $this->pos;
 }
コード例 #13
0
ファイル: LintCommand.php プロジェクト: mkemiche/Annuaire
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $twig = $this->getContainer()->get('twig');
     $template = null;
     $filename = $input->getArgument('filename');
     if (!$filename) {
         if (0 !== ftell(STDIN)) {
             throw new \RuntimeException('Please provide a filename or pipe template content to stdin.');
         }
         while (!feof(STDIN)) {
             $template .= fread(STDIN, 1024);
         }
         return $this->validateTemplate($twig, $output, $template);
     }
     if (0 !== strpos($filename, '@') && !is_readable($filename)) {
         throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
     }
     if (is_file($filename)) {
         $files = array($filename);
     } elseif (is_dir($filename)) {
         $files = Finder::create()->files()->in($filename)->name('*.twig');
     } else {
         $dir = $this->getApplication()->getKernel()->locateResource($filename);
         $files = Finder::create()->files()->in($dir)->name('*.twig');
     }
     $errors = 0;
     foreach ($files as $file) {
         $errors += $this->validateTemplate($twig, $output, file_get_contents($file), $file);
     }
     return $errors > 0 ? 1 : 0;
 }
コード例 #14
0
ファイル: FileSize.php プロジェクト: ixtrum/file-manager
 /**
  * Returns file size by using native fseek function
  *
  * @see http://www.php.net/manual/en/function.filesize.php#79023
  * @see http://www.php.net/manual/en/function.filesize.php#102135
  *
  * @return string | bool (false when fail)
  */
 private function sizeNativeSeek()
 {
     // This should work for large files on 64bit platforms and for small files every where
     $fp = fopen($this->path, "rb");
     flock($fp, LOCK_SH);
     if (!$fp) {
         return false;
     }
     $res = fseek($fp, 0, SEEK_END);
     if ($res === 0) {
         $pos = ftell($fp);
         flock($fp, LOCK_UN);
         fclose($fp);
         // $pos will be positive int if file is <2GB
         // if is >2GB <4GB it will be negative number
         if ($pos >= 0) {
             return (string) $pos;
         } else {
             return sprintf("%u", $pos);
         }
     } else {
         flock($fp, LOCK_UN);
         fclose($fp);
         return false;
     }
 }
コード例 #15
0
ファイル: vdk.php プロジェクト: abouvier/vdk
function vdk_pack($vdk, $dirname, &$table = [], &$folders = 0, $parent = null)
{
    if (!($folder = scandir($dirname))) {
        return;
    }
    usort($folder, 'strcasecmp');
    if (is_null($parent)) {
        array_splice($folder, 1, 1);
    }
    $current = ftell($vdk);
    $last = count($folder) - 1;
    foreach ($folder as $i => $filename) {
        echo $pathname = "{$dirname}/{$filename}", "\n";
        if (is_dir($pathname)) {
            $start = ftell($vdk);
            fseek($vdk, 145, SEEK_CUR);
            if (!in_array($filename, ['.', '..'])) {
                vdk_pack($vdk, $pathname, $table, $folders, $current);
                $folders++;
            }
            $end = ftell($vdk);
            fseek($vdk, $start);
            fwrite($vdk, pack('Ca128V4', 1, $filename, 0, 0, $filename == '..' ? $parent : $start + ($filename == '.' ? 0 : 145), $i == $last ? 0 : $end));
            fseek($vdk, $end);
        } else {
            $table[$pathname] = ftell($vdk);
            $data = gzcompress(file_get_contents($pathname), $GLOBALS['level']);
            fwrite($vdk, pack('Ca128V4', 0, $filename, filesize($pathname), $size = strlen($data), 0, $i == $last ? 0 : $table[$pathname] + 145 + $size) . $data);
        }
    }
}
コード例 #16
0
 /**
  * Reads and returns $_bufferSize chunk of data.
  * @return mixed buffer or -1 if EOF.
  */
 function read($len = null)
 {
     // ignore $len param, not sure how to hanlde it, since
     // this should only read bufferSize amount of data.
     if ($len !== null) {
         $this->currentPosition = ftell($this->fd);
     }
     if (($data = $this->in->read($this->bufferSize)) !== -1) {
         // not all files end with a newline character, so we also need to check EOF
         if (!$this->in->eof()) {
             $notValidPart = strrchr($data, "\n");
             $notValidPartSize = strlen($notValidPart);
             if ($notValidPartSize > 1) {
                 // Block doesn't finish on a EOL
                 // Find the last EOL and forgot all following stuff
                 $dataSize = strlen($data);
                 $validSize = $dataSize - $notValidPartSize + 1;
                 $data = substr($data, 0, $validSize);
                 // Rewind to the begining of the forgotten stuff.
                 $this->in->skip(-$notValidPartSize + 1);
             }
         }
         // if !EOF
     }
     return $data;
 }
コード例 #17
0
ファイル: muximux.php プロジェクト: homelaber/Muximux
function write_ini()
{
    unlink(CONFIG);
    $config = new Config_Lite(CONFIG);
    foreach ($_POST as $parameter => $value) {
        $splitParameter = explode('-', $parameter);
        if ($value == "on") {
            $value = "true";
        }
        $config->set($splitParameter[0], $splitParameter[1], $value);
    }
    // save object to file
    try {
        $config->save();
    } catch (Config_Lite_Exception $e) {
        echo "\n" . 'Exception Message: ' . $e->getMessage();
    }
    $cache_new = "; <?php die(\"Access denied\"); ?>";
    // Adds this to the top of the config so that PHP kills the execution if someone tries to request the config-file remotely.
    $file = CONFIG;
    // the file to which $cache_new gets prepended
    $handle = fopen($file, "r+");
    $len = strlen($cache_new);
    $final_len = filesize($file) + $len;
    $cache_old = fread($handle, $len);
    rewind($handle);
    $i = 1;
    while (ftell($handle) < $final_len) {
        fwrite($handle, $cache_new);
        $cache_new = $cache_old;
        $cache_old = fread($handle, $len);
        fseek($handle, $i * $len);
        $i++;
    }
}
コード例 #18
0
ファイル: Handler.php プロジェクト: noxian/WP-Filebase
 protected function ftell()
 {
     if ($this->data_string_flag) {
         return $this->data_string_position;
     }
     return ftell($this->getid3->fp);
 }
コード例 #19
0
ファイル: shapefile.php プロジェクト: alanblins/php-shapefile
 public function getRecord($geometry_format = self::GEOMETRY_ARRAY)
 {
     if (ftell($this->shp) >= $this->file_size) {
         return false;
     }
     $record_number = $this->ReadData('N');
     $content_length = $this->ReadData('N');
     $shape_type = $this->ReadData('V');
     if ($shape_type != 0 && $shape_type != $this->shape_type) {
         $this->Error('WRONG_RECORD_TYPE', $shape_type);
     }
     switch ($shape_type) {
         case 0:
             $shp = null;
             break;
         case 1:
             $shp = $this->ReadPoint();
             break;
         case 8:
             $shp = $this->ReadMultiPoint();
             break;
         case 3:
             $shp = $this->ReadPolyLine();
             break;
         case 5:
             $shp = $this->ReadPolygon();
             break;
     }
     if ($geometry_format == self::GEOMETRY_WKT) {
         $shp = $this->WKT($shp);
     }
     return array('shp' => $shp, 'dbf' => dbase_get_record_with_names($this->dbf, $record_number));
 }
コード例 #20
0
 /**
  * Generates configuration. Locks configuration file for exclusive access to avoid collisions. Will not be stabe on Windows.
  *
  * @return	void
  */
 public function generateConfiguration()
 {
     $fileName = PATH_site . self::AUTOCONFIGURTION_FILE;
     if (class_exists('TYPO3\\CMS\\Core\\Locking\\LockFactory')) {
         $lockFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Locking\\LockFactory');
         $lockObject = $lockFactory->createLocker($fileName, LockingStrategyInterface::LOCK_CAPABILITY_EXCLUSIVE | LockingStrategyInterface::LOCK_CAPABILITY_NOBLOCK);
         $lockObject->acquire();
     } else {
         // @deprecated since 7.6, will be removed once 6.2 support is removed
         $lockObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Locking\\Locker', $fileName, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
         $lockObject->setEnableLogging(false);
         $lockObject->acquireExclusiveLock();
     }
     $fd = @fopen($fileName, 'a+');
     if ($fd) {
         // Check size
         fseek($fd, 0, SEEK_END);
         if (ftell($fd) == 0) {
             $this->doGenerateConfiguration($fd);
         }
         fclose($fd);
         \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($fileName);
     }
     $lockObject->release();
 }
コード例 #21
0
ファイル: file.php プロジェクト: BGCX261/zoombi-svn-to-git
 public function tell()
 {
     if (!$this->isValid()) {
         return;
     }
     return ftell($this->m_handle);
 }
コード例 #22
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $twig = $this->getContainer()->get('twig');
     $template = null;
     $filename = $input->getArgument('filename');
     if (!$filename) {
         if (0 !== ftell(STDIN)) {
             throw new \RuntimeException("Please provide a filename or pipe template content to stdin.");
         }
         while (!feof(STDIN)) {
             $template .= fread(STDIN, 1024);
         }
         return $twig->parse($twig->tokenize($template));
     }
     if (0 !== strpos($filename, '@') && !is_readable($filename)) {
         throw new \RuntimeException("File or directory '%s' is not readable");
     }
     $files = array();
     if (is_file($filename)) {
         $files = array($filename);
     } elseif (is_dir($filename)) {
         $files = Finder::create()->files()->in($filename)->name('*.twig');
     } else {
         $dir = $this->getApplication()->getKernel()->locateResource($filename);
         $files = Finder::create()->files()->in($dir)->name('*.twig');
     }
     foreach ($files as $file) {
         $twig->parse($twig->tokenize(file_get_contents($file), (string) $file));
     }
     $output->writeln('<info>No syntax error detected.</info>');
 }
コード例 #23
0
ファイル: Geoip.php プロジェクト: netcon-source/apps
 /**
  * Open the GeoIP database.
  *
  * @return boolean  False on error.
  */
 protected function _open()
 {
     /* Return if we already have an object. */
     if (!empty($this->_fh)) {
         return true;
     }
     /* Return if no datafile specified. */
     if (empty($this->_datafile)) {
         return false;
     }
     $this->_fh = fopen($this->_datafile, 'rb');
     if (!$this->_fh) {
         return false;
     }
     $filepos = ftell($this->_fh);
     fseek($this->_fh, -3, SEEK_END);
     for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; ++$i) {
         $delim = fread($this->_fh, 3);
         if ($delim == chr(255) . chr(255) . chr(255)) {
             break;
         } else {
             fseek($this->_fh, -4, SEEK_CUR);
         }
     }
     fseek($this->_fh, $filepos, SEEK_SET);
     return true;
 }
コード例 #24
0
ファイル: StreamTest.php プロジェクト: crystalservice/samba
 public function testTell()
 {
     $fh = fopen(self::$shareUrl . '/LICENSE', 'r');
     static::assertSame(0, ftell($fh));
     fseek($fh, 10);
     static::assertSame(10, ftell($fh));
 }
コード例 #25
0
 public function parse()
 {
     $this->_line_number = 1;
     $this->_char_number = 1;
     $eof = false;
     while (!feof($this->_stream) && !$eof) {
         $pos = ftell($this->_stream);
         $line = stream_get_line($this->_stream, $this->_buffer_size, $this->_line_ending);
         $ended = (bool) (ftell($this->_stream) - strlen($line) - $pos);
         // if we're still at the same place after stream_get_line, we're done
         $eof = ftell($this->_stream) == $pos;
         $byteLen = strlen($line);
         for ($i = 0; $i < $byteLen; $i++) {
             if ($this->_emit_file_position) {
                 $this->_listener->file_position($this->_line_number, $this->_char_number);
             }
             $this->_consume_char($line[$i]);
             $this->_char_number++;
         }
         if ($ended) {
             $this->_line_number++;
             $this->_char_number = 1;
         }
     }
 }
コード例 #26
0
ファイル: StreamSeeker.php プロジェクト: brickoo/components
 /**
  * Returns the current position of a file pointer.
  * @link http://www.php.net/manual/en/function.ftell.php
  * @throws \Brickoo\Component\IO\Stream\Exception\InvalidResourceHandleException
  * @return integer or false on failure
  */
 public function tell()
 {
     if (!is_resource($this->streamResource)) {
         throw new InvalidResourceHandleException();
     }
     return ftell($this->streamResource);
 }
コード例 #27
0
ファイル: functions.php プロジェクト: GvarimAZA/website
function realFilesize($filename)
{
    $fp = fopen($filename, 'r');
    $return = false;
    if (is_resource($fp)) {
        if (PHP_INT_SIZE < 8) {
            if (0 === fseek($fp, 0, SEEK_END)) {
                $return = 0.0;
                $step = 0x7fffffff;
                while ($step > 0) {
                    if (0 === fseek($fp, -$step, SEEK_CUR)) {
                        $return += floatval($step);
                    } else {
                        $step >>= 1;
                    }
                }
            }
        } else {
            if (0 === fseek($fp, 0, SEEK_END)) {
                $return = ftell($fp);
            }
        }
    }
    return $return;
}
コード例 #28
0
ファイル: build.php プロジェクト: abodie/DCRM
 function getfile($name)
 {
     $handle = fopen($this->file, "rb");
     if (fread($handle, 7) == "!<arch>") {
         fread($handle, 1);
         $filesize = filesize($this->file);
         $file_output = array();
         while (ftell($handle) < $filesize - 1) {
             $filename = trim(fread($handle, 16));
             if ($filename == $name) {
                 $timestamp = trim(fread($handle, 12));
                 $owner_id = trim(fread($handle, 6));
                 $group_id = trim(fread($handle, 6));
                 $file_mode = trim(fread($handle, 8));
                 $size = trim(fread($handle, 10));
                 fread($handle, 2);
                 $content = fread($handle, $size);
                 $file_output[] = array($name, $timestamp, $owner_id, $group_id, $file_mode, $size, $content);
             } else {
                 fread($handle, 32);
                 $size = trim(fread($handle, 10));
                 fread($handle, 2);
                 fseek($handle, ftell($handle) + $size);
             }
         }
         return $file_output;
     } else {
         return false;
     }
     fclose($handle);
 }
コード例 #29
0
ファイル: TempStream.php プロジェクト: seytar/psx
 public function tell()
 {
     if ($this->resource) {
         return ftell($this->resource);
     }
     return false;
 }
コード例 #30
0
 public static function findStubLength($file, $pattern = self::PATTERN_OPEN)
 {
     if (!($fp = fopen($file, 'rb'))) {
         throw new RuntimeException(sprintf('The phar "%s" could not be opened for reading.', $file));
     }
     $stub = null;
     $offset = 0;
     $combo = str_split($pattern);
     while (!feof($fp)) {
         if (fgetc($fp) === $combo[$offset]) {
             $offset++;
             if (!isset($combo[$offset])) {
                 $stub = ftell($fp);
                 break;
             }
         } else {
             $offset = 0;
         }
     }
     fclose($fp);
     if (null === $stub) {
         throw new InvalidArgumentException(sprintf('The pattern could not be found in "%s".', $file));
     }
     return $stub;
 }