本文整理汇总了PHP中ftell函数的典型用法代码示例。如果您正苦于以下问题:PHP ftell函数的具体用法?PHP ftell怎么用?PHP ftell使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftell函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: next
/**
* 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;
}
开发者ID:crazycodr,项目名称:php-stream-iterators,代码行数:37,代码来源:CharacterBehavior.php
示例2: execute
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);
}
开发者ID:brennantom,项目名称:hackazon,代码行数:31,代码来源:YamlLintCommand.php
示例3: getValueForParameter
/**
* 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;
}
开发者ID:yonetici,项目名称:pimcore-coreshop-demo,代码行数:38,代码来源:StdIn.php
示例4: tell
function tell() : int
{
if (!is_resource($this->resource) || ($pos = ftell($this->resource)) === FALSE) {
throw new \RuntimeException('Could not tell the position');
}
return $pos;
}
开发者ID:guide42,项目名称:ochenta,代码行数:7,代码来源:Stream.php
示例5: _fstrpos
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));
}
开发者ID:neel,项目名称:bong,代码行数:7,代码来源:common.php
示例6: mkdir
*/
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);
开发者ID:RqHe,项目名称:aunet1,代码行数:61,代码来源:Upyun.class.php
示例7: execute
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);
}
开发者ID:Dren-x,项目名称:mobit,代码行数:34,代码来源:YamlLintCommand.php
示例8: getFileSize
/**
* 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));
}
开发者ID:gitter-badger,项目名称:BigFileTools,代码行数:36,代码来源:NativeSeekDriver.php
示例9: fire
/**
* {@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);
}
开发者ID:winglian,项目名称:twigbridge,代码行数:28,代码来源:Lint.php
示例10: tail
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;
}
}
}
}
开发者ID:stawen,项目名称:domovision,代码行数:60,代码来源:knx-function.php
示例11: render
/**
* @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);
}
}
开发者ID:itephp,项目名称:framework,代码行数:38,代码来源:File.php
示例12: stream_tell
function stream_tell()
{
if (!empty($this->stream)) {
return ftell($this->stream);
}
return $this->pos;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:include_userstream_002.php
示例13: execute
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;
}
开发者ID:mkemiche,项目名称:Annuaire,代码行数:31,代码来源:LintCommand.php
示例14: sizeNativeSeek
/**
* 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;
}
}
开发者ID:ixtrum,项目名称:file-manager,代码行数:34,代码来源:FileSize.php
示例15: vdk_pack
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);
}
}
}
开发者ID:abouvier,项目名称:vdk,代码行数:31,代码来源:vdk.php
示例16: read
/**
* 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;
}
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:30,代码来源:BufferedReader.php
示例17: write_ini
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++;
}
}
开发者ID:homelaber,项目名称:Muximux,代码行数:35,代码来源:muximux.php
示例18: ftell
protected function ftell()
{
if ($this->data_string_flag) {
return $this->data_string_position;
}
return ftell($this->getid3->fp);
}
开发者ID:noxian,项目名称:WP-Filebase,代码行数:7,代码来源:Handler.php
示例19: getRecord
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));
}
开发者ID:alanblins,项目名称:php-shapefile,代码行数:33,代码来源:shapefile.php
示例20: generateConfiguration
/**
* 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();
}
开发者ID:helhum,项目名称:realurl,代码行数:30,代码来源:ConfigurationGenerator.php
注:本文中的ftell函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论