本文整理汇总了PHP中fstat函数的典型用法代码示例。如果您正苦于以下问题:PHP fstat函数的具体用法?PHP fstat怎么用?PHP fstat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fstat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSizeReturnsStreamSize
public function testSizeReturnsStreamSize()
{
$stream = Stream::make('Lorem ipsum dolor sit amet');
$resource = $stream->getResource();
$stat = fstat($resource);
$this->assertEquals($stat['size'], $stream->getSize());
}
示例2: multipartUpload
function multipartUpload($client, $bucket, $keyprefix)
{
//初始化分开上传,获取uploadid
$args = array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile");
$uploadid = $client->initMultipartUpload($args);
$uploadid = $uploadid["UploadId"];
//获取到uploadid
//开始上传
$file = "D://IMG.jpg";
//要上传的文件
$partsize = 1024 * 100;
$resource = fopen($file, "r");
$stat = fstat($resource);
$total = $stat["size"];
//获取文件的总大小
fclose($resource);
$count = (int) ($total / $partsize + 1);
//计算文件需要分几块上传
for ($i = 0; $i < $count; $i++) {
//依次上传每一块
echo "upload" . $i . "\r\n";
$args = array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile", "LastPart" => $i === $count - 1, "Options" => array("partNumber" => $i + 1, "uploadId" => $uploadid), "ObjectMeta" => array("Content-Length" => min($partsize, $total - $partsize * $i)), "Content" => array("content" => $file, "seek_position" => $partsize * $i));
$etag = $client->uploadPart($args);
$etag = $etag["ETag"];
}
$parts = $client->listParts(array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile", "Options" => array("uploadId" => $uploadid)));
//结束上传
$args = array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile", "Options" => array("uploadId" => $uploadid), "Parts" => $parts["Parts"]);
$result = $client->completeMultipartUpload($args);
rangeGetAndCheckMd5($client, $bucket, $keyprefix . "EOFile", "D://testdown/down", base64_encode(md5_file("D://IMG.jpg")));
}
示例3: parse
protected function parse()
{
$streams = array();
if (!$this->readHeader()) {
throw new Exception('Unable to read header');
}
/* directories are aligned on 128 bytes */
$stats = fstat($this->fd);
for ($pos = 512 + $this->dir_start * $this->block_size; $pos < $stats[7]; $pos += 128) {
fseek($this->fd, $pos);
$name = fread($this->fd, 64);
$name_length = $this->readUnsignedShort();
$name = utf8_encode(str_replace("", '', substr($name, 0, $name_length - 2)));
$type = $this->readByte();
$color = $this->readByte();
$left_sib = $this->readUnsignedLong();
$right_sib = $this->readUnsignedLong();
$child = $this->readUnsignedLong();
fseek($this->fd, 36, SEEK_CUR);
$stream_start = $this->readUnsignedLong();
$stream_size = $this->readUnsignedLong();
switch ($type) {
case self::STGTY_STREAM:
debug('Found stream ' . $name . ' starting at sector ' . sprintf('0x%X', $stream_start) . ' of size ' . $stream_size);
$streams[] = new OLEStream($name, $this, $this->fd, $stream_start, $stream_size);
break;
case self::STGTY_ROOT:
debug('Found root ' . $name);
break;
}
}
$this->streams = $streams;
}
示例4: getSize
/**
* {@inheritdoc}
*
* @return int|null Returns the size in bytes if known, or null if unknown.
*/
public function getSize()
{
if (null === $this->stream) {
return null;
}
return fstat($this->stream)['size'];
}
示例5: eraseLastLineBreak
function eraseLastLineBreak($fileName)
{
$file = fopen($fileName, 'r+') or die("can't open file");
$stat = fstat($file);
ftruncate($file, $stat['size'] - 2);
fclose($file);
}
示例6: get
/**
* @brief Logs admin page.
*
* @return string
*/
function get()
{
$log_choices = array(LOGGER_NORMAL => 'Normal', LOGGER_TRACE => 'Trace', LOGGER_DEBUG => 'Debug', LOGGER_DATA => 'Data', LOGGER_ALL => 'All');
$t = get_markup_template('admin_logs.tpl');
$f = get_config('system', 'logfile');
$data = '';
if (!file_exists($f)) {
$data = t("Error trying to open <strong>{$f}</strong> log file.\r\n<br/>Check to see if file {$f} exist and is \n\treadable.");
} else {
$fp = fopen($f, 'r');
if (!$fp) {
$data = t("Couldn't open <strong>{$f}</strong> log file.\r\n<br/>Check to see if file {$f} is readable.");
} else {
$fstat = fstat($fp);
$size = $fstat['size'];
if ($size != 0) {
if ($size > 5000000 || $size < 0) {
$size = 5000000;
}
$seek = fseek($fp, 0 - $size, SEEK_END);
if ($seek === 0) {
$data = escape_tags(fread($fp, $size));
while (!feof($fp)) {
$data .= escape_tags(fread($fp, 4096));
}
}
}
fclose($fp);
}
}
return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Logs'), '$submit' => t('Submit'), '$clear' => t('Clear'), '$data' => $data, '$baseurl' => z_root(), '$logname' => get_config('system', 'logfile'), '$debugging' => array('debugging', t("Debugging"), get_config('system', 'debugging'), ""), '$logfile' => array('logfile', t("Log file"), get_config('system', 'logfile'), t("Must be writable by web server. Relative to your top-level webserver directory.")), '$loglevel' => array('loglevel', t("Log level"), get_config('system', 'loglevel'), "", $log_choices), '$form_security_token' => get_form_security_token('admin_logs')));
}
示例7: open
public function open($filename, $mode = "w", $permissions = 0777)
{
$created = false;
if ($this->resource !== false) {
return false;
}
if (file_exists($filename) === false) {
if ($mode == "r" || $mode == "r+") {
return false;
} else {
$created = true;
$directory = dirname($filename);
if (is_dir($directory) === false) {
mkdir($directory, $permissions, true);
chmod($directory, $permissions);
}
}
}
$this->resource = fopen($filename, $mode);
if ($this->resource !== false) {
if ($created === true) {
chmod($filename, $permissions);
}
$this->stats = fstat($this->resource);
}
return true;
}
示例8: testGetSize
public function testGetSize()
{
$resource = fopen(__FILE__, 'r');
$expected = fstat($resource);
$stream = new Stream($resource);
$this->assertEquals($expected['size'], $stream->getSize());
}
示例9: create_source_zip
function create_source_zip()
{
// get the version
$v_res = $GLOBALS['db']->query('select `version` from `version` limit 1')->fetch();
$version = $v_res['version'];
if (empty($version)) {
$version = '';
}
$zip_filename = _DIR_ROOT . '/source/latest' . $version . '.zip';
define('_SOURCE_ZIP_FILE', $zip_filename);
if (file_exists($zip_filename)) {
if (($fp = @fopen($zip_filename, 'r')) !== false) {
$stats = fstat($fp);
fclose($fp);
// check if the source was created in the last hour
if (time() - $stats['mtime'] <= 3600) {
return;
}
}
rename($zip_filename, _DIR_ROOT . '/source/latest' . time() . '.zip');
}
// Create the latest source of the application
// in a ZIP archive
$z = new ZipArchive();
$z->open($zip_filename, ZipArchive::CREATE);
add_directory_to_zip($z, _DIR_ROOT);
// define a constant with the path to the file
define('_SOURCE_ZIP_FILE', $zip_filename);
}
示例10: cacheAge
function cacheAge($cacheName)
{
$fp = fopen($this->cacheFolder . $cacheName, 'r');
$fstat = fstat($fp);
fclose($fp);
return time() - $fstat['mtime'];
}
示例11: changed
protected function changed()
{
clearstatcache();
$fstat = fstat($this->fh);
$this->currentSize = $fstat['size'];
return $this->size != $this->currentSize;
}
示例12: url_stat
function url_stat($path, $flags)
{
if (isset($this->filehandle)) {
return fstat($this->filehandle);
}
return null;
}
示例13: getFileSize
function getFileSize()
{
if (false === ($stat = fstat($this->resource))) {
throw new phpMorphy_Exception('Can`t invoke fstat for ' . $this->file_name . ' file');
}
return $stat['size'];
}
示例14: __construct
public function __construct($file)
{
$this->file = $file;
$this->handle = fopen($this->file, self::MODE);
$stats = fstat($this->handle);
$this->size = $stats['size'];
}
示例15: isDirect
/**
* {@inheritdoc}
*/
public function isDirect()
{
if ($this->isDirect === null) {
$this->isDirect = 020000 === (fstat(STDOUT)['mode'] & 0170000);
}
return $this->isDirect;
}