本文整理汇总了PHP中File::open方法的典型用法代码示例。如果您正苦于以下问题:PHP File::open方法的具体用法?PHP File::open怎么用?PHP File::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* Read a key from the cache
*
* @param string $key Identifier for the data
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
* @access public
*/
function read($key)
{
// Modifications by webligo
$key .= '.php';
// end modifications
if ($this->__setKey($key) === false || !$this->__init || !$this->__File->exists()) {
return false;
}
if ($this->settings['lock']) {
$this->__File->lock = true;
}
// Modifications by webligo
$this->__File->open('rb');
fgets($this->__File->handle);
// Strip off die
$key .= '.php';
// end modifications
$time = time();
$cachetime = intval($this->__File->read(11));
if ($cachetime !== false && ($cachetime < $time || $time + $this->settings['duration'] < $cachetime)) {
$this->__File->close();
return false;
}
$data = $this->__File->read(true);
if ($data !== '' && !empty($this->settings['serialize'])) {
if ($this->settings['isWindows']) {
$data = str_replace('\\\\\\\\', '\\', $data);
}
$data = unserialize((string) $data);
}
$this->__File->close();
return $data;
}
示例2: do_minify
function do_minify($content)
{
global $config;
$c = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize();
$url = $config->protocol . $config->host;
// Minify HTML
if (isset($c['html_minifier'])) {
$config->html_minifier = true;
Config::set('html_minifier', $config->html_minifier);
$content = Converter::detractSkeleton($content);
}
// Minify URL
if (isset($c['url_minifier']) && Text::check($content)->has('="' . $url)) {
$content = str_replace(array('="' . $url . '"', '="' . $url . '/', '="' . $url . '?', '="' . $url . '#'), array('="/"', '="/', '="?', '="#'), $content);
}
// Minify Embedded CSS
if (isset($c['css_minifier'])) {
$content = preg_replace_callback('#<style(>| .*?>)([\\s\\S]*?)<\\/style>#i', function ($matches) use($config, $c, $url) {
$css = Converter::detractShell($matches[2]);
if (isset($c['url_minifier'])) {
$css = preg_replace('#(?<=[\\s:])(src|url)\\(' . preg_quote($url, '/') . '#', '$1(', $css);
}
return '<style' . $matches[1] . $css . '</style>';
}, $content);
}
// Minify Embedded JavaScript
if (isset($c['js_minifier'])) {
$content = preg_replace_callback('#<script(>| .*?>)([\\s\\S]*?)<\\/script>#i', function ($matches) {
$js = Converter::detractSword($matches[2]);
return '<script' . $matches[1] . $js . '</script>';
}, $content);
}
return $content;
}
示例3: _rawParse
private function _rawParse($filename, $attributes)
{
App::import('Vendor', 'import.excelreader/excelreader');
$buffer = array();
if (file_exists($filename)) {
if (isset($attributes['delimiter']) && (isset($attributes['excel_reader']) && $attributes['excel_reader'])) {
$xl = new ExcelReader();
$xl->read($filename);
$tmp_array = $xl->toArray();
for ($i = 0; $i < 10; $i++) {
if (isset($tmp_array[$i])) {
$buffer[] = implode("\t", $tmp_array[$i]);
}
}
} else {
$file = new File($filename);
if ($file->open('r', true)) {
for ($i = 0; $i < 10; $i++) {
if (isset($attributes['delimiter']) && $attributes['delimiter'] != "") {
if (isset($attributes['qualifier']) && $attributes['qualifier'] != "") {
$buffer[] = @fgetcsv($file->handle, null, $attributes['delimiter'], $attributes['qualifier']);
} else {
$buffer[] = @fgetcsv($file->handle, null, $attributes['delimiter']);
}
}
}
$file->close();
} else {
// Error
}
}
}
return $buffer;
}
示例4: array
function _write()
{
// Load library
App::uses('File', 'Utility');
$translations = $this->Translation->find('all');
$trunced = array();
foreach ($translations as $t) {
$t = $t['Translation'];
if (empty($t['value'])) {
continue;
}
$lang = $t['language'];
$domain = $t['domain'];
$filePath = APP . 'Locale' . DS . $lang . DS . 'LC_MESSAGES' . DS . $domain . '.po';
$file = new File($filePath);
if (!isset($trunced[$filePath])) {
$file->open('w');
$trunced[$filePath] = true;
$file->close();
}
$append = 'msgid "' . str_replace('"', '\\"', $t['name']) . "\"\n";
$append .= 'msgstr "' . str_replace('"', '\\"', $t['value']) . "\"\n\n";
$file->write($append, 'a');
}
}
示例5: copy
/**
* Create a new file by copying the contents of an existing
* file into this directory under the given name. Unlike the
* link() method, this creates a separate file. Returns the
* directory entry.
*
* @param File $source source file to copy
* @param string $name destination file name
*
* @return DirectoryEntry created DirectoryEntry object
*/
public function copy(File $source, $name, $description = '')
{
// Copy single file?
if ($source->storage_id != '') {
$new_entry = $this->createFile($name, $description);
$new_file = $new_entry->file;
// copy contents
$source_fp = $source->open('rb');
$dest_fp = $new_file->open('wb');
stream_copy_to_stream($source_fp, $dest_fp);
fclose($dest_fp);
fclose($source_fp);
// copy attributes
$new_file->filename = $source->filename;
$new_file->restricted = $source->restricted;
$new_file->mime_type = $source->mime_type;
$new_file->size = $source->size;
$new_file->update();
return $new_entry;
}
//COPY directory
$newFolder = $this->mkdir($name, $description);
// Todo: This probably could be more sormy
$folder = StudipDirectory::get($newFolder->file_id);
$folder->filename = $newFolder->name;
$folder->store();
foreach ($source->listFiles() as $entry) {
$folder->copy($entry->file, $entry->name, $entry->description);
}
return $folder;
}
示例6: _rawParse
protected function _rawParse()
{
if (file_exists($this->filename)) {
if (isset($this->options['delimiter']) && (isset($this->options['excel_reader']) && $this->options['excel_reader'])) {
$xl = new ExcelReader();
$xl->read($this->filename);
$tmp_array = $xl->toArray();
for ($i = 0; $i < 10; $i++) {
if (isset($tmp_array[$i])) {
$buffer[] = implode("\t", $tmp_array[$i]);
}
}
} else {
$file = new File($this->filename);
if ($file->open('r', true)) {
for ($i = 0; $i < 10; $i++) {
if (isset($this->options['delimiter']) && $this->options['delimiter'] != "") {
if (isset($this->options['qualifier']) && $this->options['qualifier'] != "") {
$buffer[] = @fgetcsv($file->handle, null, $this->options['delimiter'], $this->options['qualifier']);
} else {
$buffer[] = @fgetcsv($file->handle, null, $this->options['delimiter']);
}
}
}
$file->close();
} else {
// Error
}
}
}
return $buffer;
}
示例7: open
public static function open($file)
{
$content = parent::open($file);
if ($content === false) {
return false;
}
return json_decode($content, true);
}
示例8: createFile
private function createFile()
{
//A valid test for file creation requires the absence of a file.
$this->assertFalse(file_exists("test.csv"));
$test = new File("test");
$test->open();
return $test;
}
示例9: time
/**
* Setup output source
*
* @param $datasource datasource name
* @param $save path to save folder
*/
function _setupOutput($datasource, $save)
{
if (empty($save)) {
return false;
}
$now = time();
$path = realpath($save) . DS . strftime($this->file_prefix, $now) . $datasource . strftime($this->file_suffix, $now);
$this->File = new File($path, false, 0666);
return $this->File->open('w');
}
示例10: do_remove_cache
/**
* Cache Killer
* ------------
*
* Add global cache killer for article(s) and page(s).
*
*/
function do_remove_cache()
{
global $config;
File::open(CACHE . DS . 'sitemap.cache')->delete();
File::open(CACHE . DS . 'feed.cache')->delete();
File::open(CACHE . DS . 'feeds.cache')->delete();
foreach (glob(CACHE . DS . '{feed,feeds}.*.cache', GLOB_NOSORT | GLOB_BRACE) as $cache) {
File::open($cache)->delete();
}
}
示例11: info
public static function info($folder = null, $array = false)
{
$config = Config::get();
$speak = Config::speak();
// Check whether the localized "about" file is available
if (!($info = File::exist(PLUGIN . DS . $folder . DS . 'about.' . $config->language . '.txt'))) {
$info = PLUGIN . DS . $folder . DS . 'about.txt';
}
$default = 'Title' . S . ' ' . ucwords(Text::parse($folder, '->text')) . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description);
$info = Text::toPage(File::open($info)->read($default), 'content', 'plugin:');
return $array ? $info : Mecha::O($info);
}
示例12: testFileRead
/**
* @depends testFileWrite
*/
public function testFileRead()
{
$file = File::open($this->path, 'r');
$buffer = '';
while (!$file->eof()) {
$buffer .= $file->fgets();
}
$this->assertEquals('foobar', $buffer);
// we are in read mode we cant write
$bytes = $file->fwrite('something');
$this->assertEquals(0, $bytes);
unset($file);
}
示例13: do_remove_cache
/**
* Cache Killer
* ------------
*/
function do_remove_cache()
{
global $config, $c_cache;
foreach ($c_cache->path as $path => $expire) {
$path = str_replace(array('(:any)', '(:num)', '(:all)', '(', ')', '|', '/', ':'), array('*', '[0-9]*', '*', '{', '}', ',', '.', '.'), $path) . '.cache';
if ($cache = File::exist(CACHE . DS . $path)) {
File::open($cache)->delete();
} else {
foreach (glob(CACHE . DS . $path, GLOB_NOSORT | GLOB_BRACE) as $cache) {
File::open($cache)->delete();
}
}
}
}
示例14: generate_cache_file
private function generate_cache_file()
{
try {
$cache_file = new File($this->cache_file_path);
$cache_file->open(File::WRITE);
$cache_file->lock();
$cache_file->write($this->get_parsed_content());
$cache_file->unlock();
$cache_file->close();
$cache_file->change_chmod(0666);
} catch (IOException $ex) {
throw new TemplateLoadingException('The template file cache couldn\'t been written due to this problem: ' . $ex->getMessage());
}
}
示例15: getMimeType
/**
* Recupera o Mime-type de um arquivo
* @param File $file
* @return string
*/
public function getMimeType( File $file ) {
$ret = false;
$iterator = $this->getIterator();
$parser = new MagicParser( $file , $this );
if ( !$file->isOpened() ) $file->open( 'r' );
for ( $iterator->rewind() ; $iterator->valid() ; $iterator->next() ) {
if ( ( $ret = $parser->parse( $iterator ) ) !== false ) {
break;
}
}
return $ret;
}