本文整理汇总了PHP中File::readable方法的典型用法代码示例。如果您正苦于以下问题:PHP File::readable方法的具体用法?PHP File::readable怎么用?PHP File::readable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::readable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructs a new Debug-Object.
*
* The first parameter has to be the file name with extension, but without directory. The second
* parameter has to be a valid and existing directory path with trainling directory separator
* (make sure the directory is writable). Standard value for this paramteer is null. If the
* directory is null or invalid "data/logs/" will be used. If the specified file doesn't exist
* it will created. If it is not possible to create a file a NonFatalException will be thrown.
*
* @param string File for saving the logdata
* @param string Valid Directory for saving the logfile or null (directory will be "data/logs/")
* @throws NonFatalException
*/
public function __construct($file, $dir = null) {
if ($dir === null || is_dir($dir) === false) {
$dir = 'data/logs/';
}
$this->file = new File($dir.basename($file));
if ($this->file->create() === false) {
throw new NonFatalException('Could not create log file "'.$this->file->relPath().'".');
}
if ($this->file->readable() === false || $this->file->writable() === false) {
$this->file->setPermissions(666);
}
$this->logs = array();
$this->benchmarks = array();
$this->temp = array();
}
示例2: fetch
public function fetch($key)
{
$cacheFile = CacheStorageFile::getCacheFile($key);
if (File::exists($cacheFile) && File::readable($cacheFile)) {
return @file_get_contents($cacheFile);
}
return false;
}
示例3: __construct
/**
* Constructs a new Debug-Object.
*
* The first parameter has to be the file name with extension, but without directory.
* Standard value is null, then the filename will be "internal.log".
* The second parameter has to be a valid and existing directory with trailing slash.
* Standard value is also null, then the directory will be "data/logs/" (make sure that it is writable).
* If the specified file doesn't exist, it will created.
* If it is not possible to create a file nn Exception will be thrown.
*
* @param string File for saving the logdata or null (filename is internal.log then)
* @param string Directory for saving the logfile or null (directory is data/logs/ then)
* @throws Exception
*/
public function __construct($file = null, $dir = null)
{
if ($dir == null || is_dir($dir) == false) {
$dir = 'data/logs/';
}
if ($file == null) {
$file = 'internal.log';
}
$this->file = new File($dir . basename($file));
if ($this->file->create() == false) {
throw new Exception('Could not create log file in method Debug::__construct().');
}
if ($this->file->readable() == false || $this->file->writable() == false) {
$writable = new CHMOD(666);
$this->file->setChmod($writable);
}
$this->logs = array();
$this->benchmarks = array();
$this->temp = array();
}
示例4: loadContainers
private function loadContainers($containers)
{
if (!File::exists($containers)) {
throw new Exception("Invalid container path");
}
foreach (glob("{$containers}/*.js") as $file) {
if (!File::readable($file)) {
throw new Exception("Could not read container config: {$file}");
}
if (is_dir($file)) {
// support recursive loading of sub directories
$this->loadContainers($file);
} else {
$this->loadFromFile($file);
}
}
}
示例5: open
public function open($dir, $filename, $write = false)
{
$this->_currentFile = null;
$this->_currentFileLastModified = null;
$ds = $this->getDataSource();
$file = new File($filepath = $ds->config['path'] . DS . $dir . DS . $filename, false);
if (!$file) {
return false;
}
if (!$file->readable()) {
return false;
}
if ($write && !$file->writable()) {
return false;
}
$this->_currentFile = $file;
$this->_currentFileLastChange = $file->lastChange();
return $file;
}
示例6: beforeRender
/**
* beforeRender callback function
*
* @param Controller $controller
* @return array contents for panel
*/
public function beforeRender(Controller $controller)
{
$data = array();
$dir = new Folder(LOGS);
$files = $dir->find();
foreach ($files as $log) {
$file = new File(LOGS . $log);
$name = $file->name();
$data[$name] = array();
if (!$file->readable()) {
$data[$name]['content'] = __('This log file is unreadable.');
continue;
}
$data[$name]['lastChange'] = date('Y-m-d H:i:s', $file->lastChange());
if ($file->size() > $this->readBytes) {
$file->offset(-$this->readBytes, SEEK_END);
}
$data[$name]['content'] = $file->read($this->readBytes);
}
return $data;
}
示例7: __construct
/**
* @param keyFile The file containing your private key for signing requests.
*/
public function __construct($keyFile = null)
{
$this->keyName = 'http://' . $_SERVER["HTTP_HOST"] . Config::get('web_prefix') . '/public.cer';
if (!empty($keyFile)) {
$rsa_private_key = false;
$privateKey = null;
try {
if (File::exists($keyFile)) {
if (File::readable($keyFile)) {
$rsa_private_key = @file_get_contents($keyFile);
} else {
throw new Exception("Could not read keyfile ({$keyFile}), check the file name and permission");
}
}
if (!$rsa_private_key) {
$rsa_private_key = '';
} else {
$phrase = Config::get('private_key_phrase') != '' ? Config::get('private_key_phrase') : null;
if (strpos($rsa_private_key, "-----BEGIN") === false) {
$privateKey .= "-----BEGIN PRIVATE KEY-----\n";
$chunks = str_split($rsa_private_key, 64);
foreach ($chunks as $chunk) {
$privateKey .= $chunk . "\n";
}
$privateKey .= "-----END PRIVATE KEY-----";
} else {
$privateKey = $rsa_private_key;
}
if (!($rsa_private_key = @openssl_pkey_get_private($privateKey, $phrase))) {
throw new Exception("Could not create the key");
}
}
} catch (Exception $e) {
throw new Exception("Error loading private key: " . $e);
}
$this->privateKey = $rsa_private_key;
}
}
示例8: File
/**
* Tests a file's contents against magic items
*
* @param string $file Absolute path to a file
* @param array $items
* @return mixed A string containing the MIME type of the file or false if no pattern matched
* @access private
*/
function __test($file, $items)
{
$File = new File($file);
if (!$File->readable()) {
return false;
}
$File->open('rb');
foreach ($items as $item) {
if ($result = $this->__testRecursive($File, $item)) {
return $result;
}
}
return false;
}
示例9:
/**
* Handles existent but not readable files
*
* @access protected
* @return mixed
*/
function _handleNotReadable()
{
if (!$this->__File->readable() && $this->__File->exists()) {
$message = 'File `' . $this->shortPath($this->__File->pwd()) . '`';
$message .= ' exists but is not readable.';
$this->out($message);
return true;
}
return false;
}
示例10: file
/**
* Setup for display or download the given file.
*
* If $_SERVER['HTTP_RANGE'] is set a slice of the file will be
* returned instead of the entire file.
*
* ### Options keys
*
* - name: Alternate download name
* - download: If `true` sets download header and forces file to be downloaded rather than displayed in browser
*
* @param string $path Path to file. If the path is not an absolute path that resolves
* to a file, `APP` will be prepended to the path.
* @param array $options Options See above.
* @return void
* @throws NotFoundException
*/
public function file($path, $options = array())
{
$options += array('name' => null, 'download' => null);
if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) {
throw new NotFoundException(__d('cake_dev', 'The requested file contains `..` and will not be read.'));
}
if (!is_file($path)) {
$path = APP . $path;
}
$file = new File($path);
if (!$file->exists() || !$file->readable()) {
if (Configure::read('debug')) {
throw new NotFoundException(__d('cake_dev', 'The requested file %s was not found or not readable', $path));
}
throw new NotFoundException(__d('cake', 'The requested file was not found'));
}
$extension = strtolower($file->ext());
$download = $options['download'];
if ((!$extension || $this->type($extension) === false) && $download === null) {
$download = true;
}
$fileSize = $file->size();
if ($download) {
$agent = env('HTTP_USER_AGENT');
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
$contentType = 'application/octet-stream';
} elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
$contentType = 'application/force-download';
}
if (!empty($contentType)) {
$this->type($contentType);
}
if ($options['name'] === null) {
$name = $file->name;
} else {
$name = $options['name'];
}
$this->download($name);
$this->header('Content-Transfer-Encoding', 'binary');
}
$this->header('Accept-Ranges', 'bytes');
$httpRange = env('HTTP_RANGE');
if (isset($httpRange)) {
$this->_fileRange($file, $httpRange);
} else {
$this->header('Content-Length', $fileSize);
}
$this->_clearBuffer();
$this->_file = $file;
}
示例11: grabFiles
public function grabFiles()
{
$validItems = $this->getFileRules();
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
$result = array();
foreach ($validItems as $k => &$item) {
$dir = new Folder($item['path']);
$files = $dir->find($item['regex'], true);
foreach ($files as $file) {
$f = new File($item['path'] . DS . $file);
$validItems[$k]['files'][] = array('filename' => $file, 'filesize' => $f->size(), 'read' => $f->readable(), 'write' => $f->writable(), 'execute' => $f->executable());
}
}
return $validItems;
}
示例12: parent
/**
* undocumented function
*
* @return void
*/
function parent()
{
$config = $this->config();
if ($config['id'] == 1 || empty($config['fork'])) {
return array();
}
if (!empty($config['fork'])) {
$path = Configure::read("Content.{$config['repo']['type']}") . 'repo' . DS . $config['url'] . '.git' . DS;
}
$File = new File($path . 'permissions.ini');
if (!$File->readable()) {
if (!$File->create()) {
return false;
}
}
return $File->read();
}
示例13: metadata
/**
* Retrieve (cached) metadata of a file
*
* @param Model $Model
* @param string $file An absolute path to a file
* @param integer $level level of amount of info to add, `0` disable, `1` for basic, `2` for detailed info
* @return mixed Array with results or false if file is not readable
*/
function metadata(&$Model, $file, $level = 1)
{
if ($level < 1) {
return array();
}
extract($this->settings[$Model->alias]);
$File = new File($file);
if (!$File->readable()) {
return false;
}
$checksum = $File->md5(true);
if (isset($this->__cached[$Model->alias][$checksum])) {
$data = $this->__cached[$Model->alias][$checksum];
}
if ($level > 0 && !isset($data[1])) {
$data[1] = array('size' => $File->size(), 'mime_type' => MimeType::guessType($File->pwd()), 'checksum' => $checksum);
}
if ($level > 1 && !isset($data[2])) {
$Media = Media::factory($File->pwd());
if ($Media->name === 'Audio') {
$data[2] = array('artist' => $Media->artist(), 'album' => $Media->album(), 'title' => $Media->title(), 'track' => $Media->track(), 'year' => $Media->year(), 'length' => $Media->duration(), 'quality' => $Media->quality(), 'sampling_rate' => $Media->samplingRate(), 'bit_rate' => $Media->bitRate());
} elseif ($Media->name === 'Image') {
$data[2] = array('width' => $Media->width(), 'height' => $Media->height(), 'ratio' => $Media->ratio(), 'quality' => $Media->quality(), 'megapixel' => $Media->megapixel());
} elseif ($Media->name === 'Text') {
$data[2] = array('characters' => $Media->characters(), 'syllables' => $Media->syllables(), 'sentences' => $Media->sentences(), 'words' => $Media->words(), 'flesch_score' => $Media->fleschScore(), 'lexical_density' => $Media->lexicalDensity());
} elseif ($Media->name === 'Video') {
$data[2] = array('title' => $Media->title(), 'year' => $Media->year(), 'length' => $Media->duration(), 'width' => $Media->width(), 'height' => $Media->height(), 'ratio' => $Media->ratio(), 'quality' => $Media->quality(), 'bit_rate' => $Media->bitRate());
} else {
$data[2] = array();
}
}
for ($i = $level, $result = array(); $i > 0; $i--) {
$result = array_merge($result, $data[$i]);
}
$this->__cached[$Model->alias][$checksum] = $data;
return Set::filter($result);
}
示例14: strtotime
function __loadDbItems()
{
// variable used to determine the read dir time
$acdate = strtotime("now");
// check to see whether a valid directory was passed to the script
if ($this->Session->read('User.dirname_get')) {
// if it is valid, we'll set it as the directory to read data from
$this->dirpath = $this->Session->read('User.dirname_get');
} else {
// if it is invalid, we'll use the default directory
$this->dirpath = Configure::read('default_get_dir');
}
// use Folder class
$dir = new Folder($this->dirpath);
// try to change the current working directory to the one from wich i want to read contents from
if (!$dir->cd($this->dirpath)) {
// if the change failed, I'll use the default directory
$this->dirpath = Configure::read('default_get_dir');
$dir->cd(Configure::read('default_get_dir'));
}
// once the current working directory is set, it is opened and read from
$dir_listing = $dir->read(true, false, true);
if ($dir_listing) {
// while there are still entries
foreach ($dir_listing[1] as $entry) {
// if the entry is to be shown (not part of the 'not_to_be_shown' array)
if (!in_array($entry, Configure::read('not_to_be_shown'))) {
$file = new File($entry);
if ($file->readable()) {
// store the file extension
$fext = $file->ext();
// store the filename
$fname = $file->name;
// store the lowercased extension
$lfext = strtolower($fext);
// store size of file into KB
$fsize = round($file->size() / 1024, 2);
// store date of file
$fidate = $file->lastChange();
// store dirpath with file
$finfokey = $entry;
// store absfilename
$fnameabs = $file->name();
// define check for filestatus_status (if updated)
$update_status = Configure::read('msg_items_file_unselected');
// check table fileinfo for update or insert
$file_info = $this->FileInfo->find('first', array('conditions' => array('fileinfo_id' => $finfokey), 'fields' => array('fileinfo_id', 'fileinfo_filedate')));
if (!empty($file_info)) {
$this->FileInfo->read(null, $file_info['FileInfo']['fileinfo_id']);
$this->FileInfo->set(array('fileinfo_dirname' => $this->dirpath, 'fileinfo_filename' => $fname, 'fileinfo_absfilename' => $fnameabs, 'fileinfo_ext' => $lfext, 'fileinfo_size' => $fsize, 'fileinfo_filedate' => $fidate, 'fileinfo_timenow' => $acdate));
$this->FileInfo->save();
// check data modified file is changed
if ($fidate > $file_info['FileInfo']['fileinfo_filedate']) {
$update_status = Configure::read('msg_items_file_updated');
}
} else {
$this->FileInfo->create();
$this->FileInfo->set(array('fileinfo_id' => $finfokey, 'fileinfo_dirname' => $this->dirpath, 'fileinfo_filename' => $fname, 'fileinfo_absfilename' => $fnameabs, 'fileinfo_ext' => $lfext, 'fileinfo_size' => $fsize, 'fileinfo_filedate' => $fidate, 'fileinfo_timenow' => $acdate));
$this->FileInfo->save();
}
// check table filestatus for update or insert
$file_status = $this->FileStatus->find('first', array('conditions' => array('filestatus_fileinfo_key' => $finfokey, 'filestatus_users_id' => $this->Session->read('User.id')), 'fields' => array('filestatus_id', 'filestatus_status')));
if (!empty($file_status)) {
if ($file_status['FileStatus']['filestatus_status'] == Configure::read('msg_items_file_selected') && $update_status != Configure::read('msg_items_file_updated')) {
$update_status = Configure::read('msg_items_file_selected');
}
$this->FileStatus->read(null, $file_status['FileStatus']['filestatus_id']);
$this->FileStatus->set(array('filestatus_status' => $update_status, 'filestatus_users_id' => $this->Session->read('User.id'), 'filestatus_timenow' => $acdate));
$this->FileStatus->save();
} else {
$this->FileStatus->create();
$this->FileStatus->set(array('filestatus_fileinfo_key' => $finfokey, 'filestatus_status' => $update_status, 'filestatus_users_id' => $this->Session->read('User.id'), 'filestatus_timenow' => $acdate));
$this->FileStatus->save();
}
}
}
}
// check consistency : delete from db files that's removed from directory
$file_info_del = $this->FileInfo->deleteAll(array('fileinfo_timenow < ' => $acdate));
if (!$file_info_del) {
$this->log('DownloadsController:__loadDbItems - Unable delete FileInfo model record', Configure::read('log_file'));
}
// check consistency : delete from db files that's removed from directory
$file_status_del = $this->FileStatus->deleteAll(array('filestatus_timenow < ' => $acdate, 'filestatus_users_id' => $this->Session->read('User.id')));
if (!$file_status_del) {
$this->log('DownloadsController:__loadDbItems - Unable delete FileStatus model record', Configure::read('log_file'));
}
}
}
示例15: get
public function get($key, $expiration = false)
{
if (!$expiration) {
// if no expiration time was given, fall back on the global config
$expiration = Config::get('cache_time');
}
$cacheFile = $this->getCacheFile($key);
// See if this cache file is locked, if so we wait upto 5 seconds for the lock owning process to
// complete it's work. If the lock is not released within that time frame, it's cleaned up.
// This should give us a fair amount of 'Cache Stampeding' protection
if ($this->isLocked($cacheFile)) {
$this->waitForLock($cacheFile);
}
if (File::exists($cacheFile) && File::readable($cacheFile)) {
$now = time();
if (($mtime = @filemtime($cacheFile)) !== false && $now - $mtime < $expiration) {
if (($data = @file_get_contents($cacheFile)) !== false) {
$data = unserialize($data);
return $data;
}
}
}
return false;
}