本文整理汇总了PHP中stat函数的典型用法代码示例。如果您正苦于以下问题:PHP stat函数的具体用法?PHP stat怎么用?PHP stat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCache
public static function getCache($dir, $cacheName, $maxAge, $deserialize = false, $plainCache = false)
{
if (is_dir($dir)) {
$cacheFile = $dir . $cacheName;
if (is_file($cacheFile)) {
// get file stats
$fileInfo = stat($cacheFile);
$lastModified = $fileInfo['mtime'];
$now = mktime();
//echo '<p>time now = ' . $now;
$diff = $now - $lastModified;
//echo '<p>time elapsed = ' .$diff;
if ($diff >= $maxAge) {
//echo 'clearing cache';
unlink($cacheFile);
return false;
}
//echo '<p>returning cache';
if ($deserialize == false && $plainCache == false) {
include_once $cacheFile;
} else {
if ($deserialize == false && $plainCache) {
$data = file_get_contents($cacheFile);
} else {
$data = unserialize(file_get_contents($cacheFile));
}
}
return $data;
} else {
return false;
}
}
}
示例2: template
/**
* Compiles a template and writes it to a cache file, which is used for inclusion.
*
* @param string $file The full path to the template that will be compiled.
* @param array $options Options for compilation include:
* - `path`: Path where the compiled template should be written.
* - `fallback`: Boolean indicating that if the compilation failed for some
* reason (e.g. `path` is not writable), that the compiled template
* should still be returned and no exception be thrown.
* @return string The compiled template.
*/
public static function template($file, array $options = array())
{
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
$defaults = array('path' => $cachePath, 'fallback' => false);
$options += $defaults;
$stats = stat($file);
$oname = basename(dirname($file)) . '_' . basename($file, '.php');
$oname .= '_' . ($stats['ino'] ?: hash('md5', $file));
$template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
$template = "{$options['path']}/{$template}";
if (file_exists($template)) {
return $template;
}
$compiled = static::compile(file_get_contents($file));
if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
if ($expired !== $template) {
unlink($expired);
}
}
return $template;
}
if ($options['fallback']) {
return $file;
}
throw new TemplateException("Could not write compiled template `{$template}` to cache.");
}
示例3: __construct
/**
* constructor
*
* @param string $path the path to a file or folder
*/
function __construct($path = null)
{
if (!is_null($path)) {
if (file_exists($path)) {
$this->filePath = $path;
if (is_file($this->filePath)) {
$this->fileStat = @stat($path);
$this->fileInfo['size'] = $this->fileStat[7];
$this->fileInfo['atime'] = $this->fileStat[8];
$this->fileInfo['ctime'] = $this->fileStat[10];
$this->fileInfo['mtime'] = $this->fileStat[9];
$this->fileInfo['path'] = $path;
$this->fileInfo['name'] = basename($path);
$this->fileInfo['is_writable'] = $this->isWritable();
$this->fileInfo['is_readable'] = $this->isReadable();
} elseif (is_dir($this->filePath)) {
$this->fileStat = @stat($path);
$this->fileInfo['name'] = basename($path);
$this->fileInfo['path'] = $path;
$this->fileInfo['atime'] = $this->fileStat[8];
$this->fileInfo['ctime'] = $this->fileStat[10];
$this->fileInfo['mtime'] = $this->fileStat[9];
$this->fileInfo['is_writable'] = $this->isWritable();
$this->fileInfo['is_readable'] = $this->isReadable();
}
} else {
trigger_error('No such file exists. ' . $path, E_USER_NOTICE);
}
}
}
示例4: ftok
function ftok($pathname, $id)
{
if (!($s = stat($pathname))) {
return -1;
}
return sprintf('%u', ord($id[0]) << 24 | ($s['dev'] & 0xff) << 16 | $s['ino'] & 0xffff);
}
示例5: loadFromFile
/**
* Load properties from a given file properties
*
* @param $file string The filename to scan
* @param $contents boolean Load the contents
* @param $loadId boolean Load id from database
* @return boolean result
*/
function loadFromFile($file, $contents = false, $loadId = false)
{
if (!JFile::exists($file) && !JFolder::exists($file . DS)) {
return false;
}
$info = @stat($file);
$this->scandate = $this->_db->getNullDate();
$this->filename = basename($file);
$this->fullpath = $file;
$this->permission = fileperms($file) & 0777;
$this->size = filesize($file);
$ctime =& JFactory::getDate($info['ctime']);
$mtime =& JFactory::getDate($info['mtime']);
$this->ctime = $ctime->toMySQL();
$this->mtime = $mtime->toMySQL();
$this->uid = $info['uid'];
$this->gid = $info['gid'];
$this->type = '';
if (is_file($file)) {
$this->type = 'file';
$this->hash_md = md5_file($file);
if ($contents) {
$f = new JD_File($file);
$this->contents = $f->read();
}
} elseif (is_dir($file)) {
$this->type = 'dir';
}
if ($loadId) {
$this->_db->setQuery('SELECT id FROM #__jdefender_filesystem WHERE fullpath = ' . $this->fullpath . ' LIMIT 1');
$this->id = $this->_db->loadResult();
}
return true;
}
示例6: listFiles
function listFiles()
{
$validExtensions = array('css', 'php', 'jpg', 'jpeg', 'gif', 'png', 'html', 'js', 'sql', 'flv');
$files = array();
$i = 0;
if ($handle = opendir($this->path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_file($this->path . $file)) {
$extn = explode('.', $file);
$ext = array_pop($extn);
if (in_array($ext, $validExtensions)) {
$fstat = stat($this->path . $file);
$files[$i]['name'] = $file;
$files[$i]['lastModifiedNice'] = date("M d Y H:i:s", $fstat['mtime']);
$files[$i]['lastModified'] = $fstat['mtime'];
$files[$i]['size'] = $fstat['size'];
//FUNCTION SCALE
$files[$i]['ext'] = $ext;
$i++;
}
}
}
closedir($handle);
}
//$this->f=$dirs;
//$files=columnSort($files,array('name'));
return $files;
}
示例7: ReadData
function ReadData($targetString, &$map, &$mapItem)
{
$data[IN] = null;
$data[OUT] = null;
$data_time = 0;
$matches = 0;
if (preg_match($this->regexpsHandled[0], $targetString, $matches)) {
$dataFileName = $matches[1];
$dataItemName = $matches[2];
}
if (!file_exists($dataFileName)) {
wm_warn("WMData ReadData: {$dataFileName} doesn't exist [WMWMDATA01]");
return array(null, null, 0);
}
$fileHandle = fopen($targetString, "r");
if (!$fileHandle) {
wm_warn("WMData ReadData: Couldn't open ({$dataFileName}). [WMWMDATA02]\n");
return array(null, null, 0);
}
list($found, $data) = $this->findDataItem($fileHandle, $dataItemName, $data);
if ($found === true) {
$stats = stat($dataFileName);
$data_time = $stats['mtime'];
} else {
wm_warn("WMData ReadData: Data name '{$dataItemName}' didn't exist in '{$dataFileName}'. [WMWMDATA03]\n");
}
wm_debug(sprintf("WMData ReadData: Returning (%s, %s, %s)\n", string_or_null($data[IN]), string_or_null($data[OUT]), $data_time));
return array($data[IN], $data[OUT], $data_time);
}
示例8: testFields
function testFields()
{
$dir = PhutilDirectoryFixture::newEmptyFixture();
$root = realpath($dir->getPath());
$watch = $this->watch($root);
$this->assertFileList($root, array());
$this->watchmanCommand('log', 'debug', 'XXX: touch a');
touch("{$root}/a");
$this->assertFileList($root, array('a'));
$query = $this->watchmanCommand('query', $root, array('fields' => array('name', 'exists', 'new', 'size', 'mode', 'uid', 'gid', 'mtime', 'mtime_ms', 'mtime_us', 'mtime_ns', 'mtime_f', 'ctime', 'ctime_ms', 'ctime_us', 'ctime_ns', 'ctime_f', 'ino', 'dev', 'nlink', 'oclock', 'cclock'), 'since' => 'n:foo'));
$this->assertEqual(null, idx($query, 'error'));
$this->assertEqual(1, count($query['files']));
$file = $query['files'][0];
$this->assertEqual('a', $file['name']);
$this->assertEqual(true, $file['exists']);
$this->assertEqual(true, $file['new']);
$stat = stat("{$root}/a");
$compare_fields = array('size', 'mode', 'uid', 'gid', 'ino', 'dev', 'nlink');
foreach ($compare_fields as $field) {
$this->assertEqual($stat[$field], $file[$field], $field);
}
$time_fields = array('mtime', 'ctime');
foreach ($time_fields as $field) {
$this->assertTimeEqual($stat[$field], $file[$field], $file[$field . '_ms'], $file[$field . '_us'], $file[$field . '_ns'], $file[$field . '_f']);
}
$this->assertRegex('/^c:\\d+:\\d+:\\d+:\\d+$/', $file['cclock'], "cclock looks clocky");
$this->assertRegex('/^c:\\d+:\\d+:\\d+:\\d+$/', $file['oclock'], "oclock looks clocky");
}
示例9: load
public function load($tpl, &$mode)
{
$src_fn = $this->sourcedir . "/" . $tpl;
$transc_fn = $this->transcompileddir . "/" . $tpl . ".php";
if ($mode == StorageAccess::MODE_SOURCE) {
$content = @file_get_contents($src_fn);
if ($content === false) {
throw new CantLoadTemplate("Template not found.");
}
return $content;
}
$src_stat = @stat($src_fn);
$transc_stat = @stat($transc_fn);
if ($src_stat === false and $transc_stat === false) {
throw new CantLoadTemplate("Template not found.");
} else {
if ($transc_stat === false) {
$mode = StorageAccess::MODE_SOURCE;
return file_get_contents($src_fn);
} else {
if ($src_stat === false) {
include $transc_fn;
return $transcompile_fx;
} else {
if ($src_stat["mtime"] > $transc_stat["mtime"]) {
$mode = StorageAccess::MODE_SOURCE;
return file_get_contents($src_fn);
} else {
include $transc_fn;
return $transcompile_fx;
}
}
}
}
}
示例10: load
static function load($file, $schema)
{
# A preparsed schemafile will have a .sqlc extension
$file_bits = explode(".", $file);
array_pop($file_bits);
$sqlc_file = implode(".", $file_bits) . ".sqlc";
$sqlc = @stat($sqlc_file);
$sql = @stat($file);
if (!$sql) {
throw new Modyllic_Loader_Exception("{$file}: File not found.");
} else {
if (!$sqlc or $sqlc[7] == 0 or $sqlc[9] < $sql[9]) {
if (($data = @file_get_contents($file)) === false) {
throw new Modyllic_Loader_Exception("Error opening {$file}");
}
$parser = new Modyllic_Parser();
$parser->partial($schema, $data, $file, ";");
} else {
if (($data = @file_get_contents($sqlc_file)) === false) {
throw new Modyllic_Loader_Exception("Error opening {$sqlc_file}");
}
$subschema = unserialize($data);
if ($subschema === FALSE) {
throw new Modyllic_Loader_Exception("Error unserializing {$sqlc_file}");
}
$schema->merge($subschema);
}
}
}
示例11: _getListFiles
public function _getListFiles()
{
$files = array();
if (is_dir($this->fullpath) && ($handle = opendir($this->fullpath))) {
$i = 0;
// check each files ...
while (false !== ($file = readdir($handle))) {
// do not display . and the root ..
if ($file == '.' || $file == '..') {
continue;
}
$object = new stdClass();
$file_stat = stat($this->fullpath . $file);
// make the link depending on if it's a file or a dir
$object->is_dir = false;
$object->is_file = true;
$object->link = '<a href="' . get_url('sidebarlink/view' . $this->path . $file) . '">' . $file . '</a>';
$object->name = $file;
// humain size
$object->size = convert_size($file_stat['size']);
// permission
list($object->perms, $object->chmod) = $this->_getPermissions($this->fullpath . $file);
// date modification
$object->mtime = date('D, j M, Y', $file_stat['mtime']);
$files[$object->name] = $object;
$i++;
}
// while
closedir($handle);
}
uksort($files, 'strnatcmp');
return $files;
}
示例12: get
/**
* @param string $filename
* @param string $path
* @return Map
* @throws \InvalidArgumentException
*/
function get($filename, $path)
{
if (mb_detect_encoding($filename, 'UTF-8', true) === false) {
$utf8Filename = utf8_encode($filename);
} else {
$utf8Filename = $filename;
}
if (!file_exists($this->mapDirectory . $path . $filename)) {
$this->db()->execute('DELETE FROM Maps WHERE path=%s AND filename=%s', $this->db()->quote($path), $this->db()->quote($utf8Filename));
throw new \InvalidArgumentException($this->mapDirectory . $path . $utf8Filename . ': file does not exist');
}
$fileStats = stat($this->mapDirectory . $path . $filename);
$result = $this->db()->execute('SELECT * FROM Maps WHERE path=%s AND filename=%s AND size=%d AND mTime=FROM_UNIXTIME(%d)', $this->db()->quote($path), $this->db()->quote($utf8Filename), $fileStats['size'], $fileStats['mtime']);
if (!$result->recordCount()) {
$mapInfo = \DedicatedManager\Utils\GbxReader\Map::read($this->mapDirectory . $path . $filename);
$map = new Map();
$fields = array('uid', 'name', 'environment', 'mood', 'type', 'displayCost', 'nbLaps', 'authorLogin', 'authorNick', 'authorZone', 'authorTime', 'goldTime', 'silverTime', 'bronzeTime', 'authorScore', 'size', 'mTime');
$this->db()->execute('INSERT INTO Maps(path, filename, %s) ' . 'VALUES (%s,%s,%s,%s,%s,%s,%s,%d,%d,%s,%s,%s,%d,%d,%d,%d,%d,%d,FROM_UNIXTIME(%d)) ' . 'ON DUPLICATE KEY UPDATE ' . \ManiaLib\Database\Tools::getOnDuplicateKeyUpdateValuesString($fields), implode(',', $fields), $this->db()->quote($map->path = $path), $this->db()->quote($map->filename = $utf8Filename), $this->db()->quote($map->uid = $mapInfo->uid), $this->db()->quote($map->name = $mapInfo->name), $this->db()->quote($map->environment = $mapInfo->environment), $this->db()->quote($map->mood = $mapInfo->mood), $this->db()->quote($map->type = $mapInfo->type), $map->displayCost = $mapInfo->displayCost, $map->nbLaps = $mapInfo->nbLaps, $this->db()->quote($map->authorLogin = $mapInfo->author->login), $this->db()->quote($map->authorNick = $mapInfo->author->nickname), $this->db()->quote($map->authorZone = $mapInfo->author->zone), $map->authorTime = $mapInfo->authorTime, $map->goldTime = $mapInfo->goldTime, $map->silverTime = $mapInfo->silverTime, $map->bronzeTime = $mapInfo->bronzeTime, $map->authorScore = $mapInfo->authorScore, $fileStats['size'], $fileStats['mtime']);
if ($mapInfo->thumbnail) {
imagejpeg($mapInfo->thumbnail, MANIALIB_APP_PATH . '/www/media/images/thumbnails/' . $map->uid . '.jpg', 100);
}
} else {
$map = Map::fromRecordSet($result);
}
return $map;
}
示例13: validate
/**
* 最小値のチェックを行う
*
* @access public
* @param string $name フォームの名前
* @param mixed $var フォームの値
* @param array $params プラグインのパラメータ
*/
public function validate($name, $var, $params)
{
$true = true;
$type = $this->getFormType($name);
if (isset($params['min']) == false || $this->isEmpty($var, $type)) {
return $true;
}
switch ($type) {
case VAR_TYPE_INT:
if ($var < $params['min']) {
if (isset($params['error'])) {
$msg = $params['error'];
} else {
$msg = _et('Please input more than %d(int) to {form}.');
}
return Ethna::raiseNotice($msg, E_FORM_MIN_INT, array($params['min']));
}
break;
case VAR_TYPE_FLOAT:
if ($var < $params['min']) {
if (isset($params['error'])) {
$msg = $params['error'];
} else {
$msg = _et('Please input more than %f(float) to {form}.');
}
return Ethna::raiseNotice($msg, E_FORM_MIN_FLOAT, array($params['min']));
}
break;
case VAR_TYPE_DATETIME:
$t_min = strtotime($params['min']);
$t_var = strtotime($var);
if ($t_var < $t_min) {
if (isset($params['error'])) {
$msg = $params['error'];
} else {
$msg = _et('Please input datetime value %s or later to {form}.');
}
return Ethna::raiseNotice($msg, E_FORM_MIN_DATETIME, array($params['min']));
}
break;
case VAR_TYPE_FILE:
$st = stat($var['tmp_name']);
if ($st[7] < $params['min'] * 1024) {
if (isset($params['error'])) {
$msg = $params['error'];
} else {
$msg = _et('Please specify file whose size is more than %d KB.');
}
return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min']));
}
break;
case VAR_TYPE_STRING:
$params['mbstrmin'] = $params['min'];
unset($params['min']);
$vld = $this->plugin->getPlugin('Validator', 'Mbstrmin');
return $vld->validate($name, $var, $params);
break;
}
return $true;
}
示例14: stream_open
/**
* Opens the script file and converts markup.
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
// get the view script source
$path = str_replace('zend.view://', '', $path);
$this->_data = file_get_contents($path);
/**
* If reading the file failed, update our local stat store
* to reflect the real stat of the file, then return on failure
*/
if ($this->_data === false) {
$this->_stat = stat($path);
return false;
}
/**
* Call callbacks
*
*/
foreach (self::getWrappers() as $wrapper) {
$this->_data = $wrapper->process($this->_data);
}
/**
* file_get_contents() won't update PHP's stat cache, so we grab a stat
* of the file to prevent additional reads should the script be
* requested again, which will make include() happy.
*/
$this->_stat = stat($path);
return true;
}
示例15: cleanupTempDirectory
function cleanupTempDirectory($dir, $force = false)
{
$dir = str_replace('\\', '/', $dir);
if (strpos($dir, '/tmp') === false) {
return;
}
$dh = opendir($dir);
while (($name = readdir($dh)) !== false) {
if (substr($name, 0, 1) == '.') {
continue;
}
$kti = substr($name, 0, 3) == 'kti';
// remove files starting with kti (indexer temp files created by open office)
$fullname = $dir . '/' . $name;
if (!$kti && !$force) {
$info = stat($fullname);
if ($info['ctime'] >= time() - 24 * 60 * 60) {
continue;
}
// remove files that have been accessed in the last 24 hours
}
if (is_dir($fullname)) {
cleanupTempDirectory($fullname, true);
rmdir($fullname);
} else {
unlink($fullname);
}
}
closedir($dh);
}