本文整理汇总了PHP中File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isUpToDate
/**
* Verifica se os menus do banco estão atualizados com os do arquivo
* @param $aDados- array de menus do banco
* @return boolean
*/
public function isUpToDate($aDados)
{
$aDados = Set::combine($aDados, "/Menu/id", "/Menu");
App::import("Xml");
App::import("Folder");
App::import("File");
$sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus");
$oFolder = new Folder($sCaminhosArquivos);
$aConteudo = $oFolder->read();
$aArquivos = Set::sort($aConteudo[1], "{n}", "desc");
if (empty($aArquivos)) {
return false;
}
$oFile = new File($sCaminhosArquivos . $aArquivos[0]);
$oXml = new Xml($oFile->read());
$aAntigo = $oXml->toArray();
foreach ($aDados as &$aMenu) {
$aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']);
}
if (isset($aAntigo["menus"])) {
$aAntigo["Menus"] = $aAntigo["menus"];
unset($aAntigo["menus"]);
}
if (isset($aAntigo["Menus"])) {
$aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu");
$aRetorno = Set::diff($aDados, $aAntigo);
}
return empty($aRetorno);
}
示例2: buildCss
public function buildCss()
{
App::import('Vendor', 'AssetMinify.JSMinPlus');
// Ouverture des fichiers de config
$dir = new Folder(Configure::read('App.www_root') . 'css' . DS . 'minified');
if ($dir->path !== null) {
foreach ($dir->find('config_.*.ini') as $file) {
preg_match('`^config_(.*)\\.ini$`', $file, $grep);
$file = new File($dir->pwd() . DS . $file);
$ini = parse_ini_file($file->path, true);
$fileFull = new File($dir->path . DS . 'full_' . $grep[1] . '.css', true, 0644);
$fileGz = new File($dir->path . DS . 'gz_' . $grep[1] . '.css', true, 0644);
$contentFull = '';
foreach ($ini as $data) {
// On a pas de version minifié
if (!($fileMin = $dir->find('file_' . md5($data['url'] . $data['md5']) . '.css'))) {
$fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css', true, 0644);
$this->out("Compression de " . $data['file'] . ' ... ', 0);
$fileMin->write(MinifyUtils::compressCss(MinifyUtils::cssAbsoluteUrl($data['url'], file_get_contents($data['file']))));
$this->out('OK');
} else {
$fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css');
}
$contentFull .= $fileMin->read() . PHP_EOL;
}
// version full
$fileFull->write($contentFull);
$fileFull->close();
// compression
$fileGz->write(gzencode($contentFull, 6));
}
}
}
示例3: _write
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');
}
}
示例4: testDeletingFileMarksBackedPagesAsBroken
public function testDeletingFileMarksBackedPagesAsBroken()
{
// Test entry
$file = new File();
$file->Filename = 'test-file.pdf';
$file->write();
$obj = $this->objFromFixture('Page', 'content');
$obj->Content = sprintf('<p><a href="[file_link,id=%d]">Working Link</a></p>', $file->ID);
$obj->write();
$this->assertTrue($obj->doPublish());
// Confirm that it isn't marked as broken to begin with
$obj->flushCache();
$obj = DataObject::get_by_id("SiteTree", $obj->ID);
$this->assertEquals(0, $obj->HasBrokenFile);
$liveObj = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = {$obj->ID}");
$this->assertEquals(0, $liveObj->HasBrokenFile);
// Delete the file
$file->delete();
// Confirm that it is marked as broken in both stage and live
$obj->flushCache();
$obj = DataObject::get_by_id("SiteTree", $obj->ID);
$this->assertEquals(1, $obj->HasBrokenFile);
$liveObj = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = {$obj->ID}");
$this->assertEquals(1, $liveObj->HasBrokenFile);
}
示例5: getContentPreview
/**
* Returns an abstract of the file content.
*
* @return string
*/
public function getContentPreview()
{
if ($this->contentPreview === null) {
$this->contentPreview = '';
if (ATTACHMENT_ENABLE_CONTENT_PREVIEW && !$this->isBinary && $this->attachmentSize != 0) {
try {
$file = new File(WCF_DIR . 'attachments/attachment-' . $this->attachmentID, 'rb');
$this->contentPreview = $file->read(2003);
$file->close();
if (CHARSET == 'UTF-8') {
if (!StringUtil::isASCII($this->contentPreview) && !StringUtil::isUTF8($this->contentPreview)) {
$this->contentPreview = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $this->contentPreview);
}
$this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
if (strlen($this->contentPreview) < $file->filesize()) {
$this->contentPreview .= '...';
}
} else {
if (StringUtil::isUTF8($this->contentPreview)) {
$this->contentPreview = '';
} else {
$this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
if ($file->filesize() > 500) {
$this->contentPreview .= '...';
}
}
}
} catch (Exception $e) {
}
// ignore errors
}
}
return $this->contentPreview;
}
示例6: upload
/**
* Handle all files
* @return void
*/
public function upload()
{
foreach ($this->files as $source => $dest) {
$file = new File($source);
$file->move($dest['path'], $dest['filename']);
}
}
示例7: afterSave
/**
* afterSave
*
* Write out the routes.php file
*/
public function afterSave($created, $options = array())
{
$aliases = $this->find('all');
$routes = '';
foreach ($aliases as $alias) {
$alias['Alias']['name'] = $alias['Alias']['name'] == 'home' ? '' : $alias['Alias']['name'];
// keyword home is the homepage
$plugin = !empty($alias['Alias']['plugin']) ? '/' . $alias['Alias']['plugin'] : null;
$controller = !empty($alias['Alias']['controller']) ? '/' . $alias['Alias']['controller'] : null;
$action = !empty($alias['Alias']['action']) ? '/' . $alias['Alias']['action'] : null;
$value = !empty($alias['Alias']['value']) ? '/' . $alias['Alias']['value'] : null;
$url = $plugin . $controller . $action . $value;
$routes .= 'Router::redirect(\'' . $url . '\', \'/' . $alias['Alias']['name'] . '\', array(\'status\' => 301));' . PHP_EOL;
$routes .= 'Router::connect(\'/' . $alias['Alias']['name'] . '\', array(\'plugin\' => \'' . $alias['Alias']['plugin'] . '\', \'controller\' => \'' . $alias['Alias']['controller'] . '\', \'action\' => \'' . $alias['Alias']['action'] . '\', \'' . implode('\', \'', explode('/', $alias['Alias']['value'])) . '\'));' . PHP_EOL;
}
App::uses('File', 'Utility');
$file = new File(ROOT . DS . SITE_DIR . DS . 'Config' . DS . 'routes.php');
$currentRoutes = str_replace(array('<?php ', '<?php'), '', explode('// below this gets overwritten', $file->read()));
$routes = '<?php ' . $currentRoutes[0] . '// below this gets overwritten' . PHP_EOL . PHP_EOL . $routes;
if ($file->write($routes)) {
$file->close();
} else {
$file->close();
// Be sure to close the file when you're done
throw new Exception(__('Error writing routes file'));
}
// <?php
// Router::redirect('/webpages/webpages/view/113', '/lenovo', array('status' => 301));
// Router::connect('/lenovo', array('plugin' => 'webpages', 'controller' => 'webpages', 'action' => 'view', 113));
}
示例8: uploadFileToStorage
public static function uploadFileToStorage(File $file)
{
$filename = 'file_' . substr(md5(uniqid(rand())), 6) . '_' . $file->getClientOriginalName();
$path = self::uploadPath();
$file->move($path, $filename);
return $path . DIRECTORY_SEPARATOR . $filename;
}
示例9: testShouldValidateObjects
/**
* @covers Respect\Validation\Rules\File::validate
*/
public function testShouldValidateObjects()
{
$rule = new File();
$object = $this->createMock('SplFileInfo', ['isFile'], ['somefile.txt']);
$object->expects($this->once())->method('isFile')->will($this->returnValue(true));
$this->assertTrue($rule->validate($object));
}
示例10: database
/**
* Step 1: database
*
* @return void
*/
function database()
{
$this->pageTitle = __('Step 1: Database', true);
if (!empty($this->data)) {
// test database connection
if (mysql_connect($this->data['Install']['host'], $this->data['Install']['login'], $this->data['Install']['password']) && mysql_select_db($this->data['Install']['database'])) {
// rename database.php.install
rename(APP . 'config' . DS . 'database.php.install', APP . 'config' . DS . 'database.php');
// open database.php file
App::import('Core', 'File');
$file = new File(APP . 'config' . DS . 'database.php', true);
$content = $file->read();
// write database.php file
$content = str_replace('{default_host}', $this->data['Install']['host'], $content);
$content = str_replace('{default_login}', $this->data['Install']['login'], $content);
$content = str_replace('{default_password}', $this->data['Install']['password'], $content);
$content = str_replace('{default_database}', $this->data['Install']['database'], $content);
// The database import script does not support prefixes at this point
$content = str_replace('{default_prefix}', '', $content);
if ($file->write($content)) {
$this->redirect(array('action' => 'data'));
} else {
$this->Session->setFlash(__('Could not write database.php file.', true));
}
} else {
$this->Session->setFlash(__('Could not connect to database.', true));
}
}
}
示例11: saveAsThumbnail
public function saveAsThumbnail($folderPath, $fileName_withExtension, $targetHeight, $targetWidth)
{
/* load up the image */
$image = Yii::app()->image->load($this->filePath);
/* determine the original image property landscape or protrait */
$imageWidth = $image->width;
$imageHeight = $image->height;
$isImageLandscape = $imageWidth > $imageHeight;
$isImageProtrait = $imageHeight > $imageWidth;
$isImageSquare = $imageHeight == $imageWidth;
/* determine the target image property */
$isTargetImageLandscape = $targetWidth > $targetHeight;
$isTargetImageProtrait = $targetHeight > $targetWidth;
$isTargetImageSquare = $targetHeight == $targetWidth;
$finalImagePath = $folderPath . '/' . $fileName_withExtension;
if (file_exists($finalImagePath)) {
$file = new File($finalImagePath);
$file->delete();
}
$image->resize($targetWidth, $targetHeight, Image::WIDTH);
$resizeFactor = $targetWidth / $imageWidth;
$resizedImageHeight = ceil($imageHeight * $resizeFactor);
if ($resizedImageHeight < $targetHeight) {
$image->crop($targetHeight, $targetWidth);
$image->resize($targetWidth, $targetHeight, Image::HEIGHT);
} else {
if ($resizedImageHeight > $targetHeight) {
$image->crop($targetHeight, $targetWidth);
}
}
$image->save($finalImagePath);
return $finalImagePath;
//$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20);
//$image->save(); // or $image->save('images/small.jpg');
}
示例12: SubsiteList
public function SubsiteList()
{
if ($this->owner->class == 'AssetAdmin') {
// See if the right decorator is there....
$file = new File();
if (!$file->hasExtension('FileSubsites')) {
return false;
}
}
$list = $this->Subsites();
$currentSubsiteID = Subsite::currentSubsiteID();
if ($list->Count() > 1) {
$output = '<select id="SubsitesSelect">';
foreach ($list as $subsite) {
$selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : '';
$output .= "\n<option value=\"{$subsite->ID}\"{$selected}>" . htmlspecialchars($subsite->Title, ENT_QUOTES) . "</option>";
}
$output .= '</select>';
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
return $output;
} else {
if ($list->Count() == 1) {
return $list->First()->Title;
}
}
}
示例13: testWritingSubsiteID
function testWritingSubsiteID()
{
$this->objFromFixture('Member', 'admin')->logIn();
$subsite = $this->objFromFixture('Subsite', 'domaintest1');
FileSubsites::$default_root_folders_global = true;
Subsite::changeSubsite(0);
$file = new File();
$file->write();
$file->onAfterUpload();
$this->assertEquals((int) $file->SubsiteID, 0);
Subsite::changeSubsite($subsite->ID);
$this->assertTrue($file->canEdit());
$file = new File();
$file->write();
$this->assertEquals((int) $file->SubsiteID, 0);
$this->assertTrue($file->canEdit());
FileSubsites::$default_root_folders_global = false;
Subsite::changeSubsite($subsite->ID);
$file = new File();
$file->write();
$this->assertEquals($file->SubsiteID, $subsite->ID);
// Test inheriting from parent folder
$folder = new Folder();
$folder->write();
$this->assertEquals($folder->SubsiteID, $subsite->ID);
FileSubsites::$default_root_folders_global = true;
$file = new File();
$file->ParentID = $folder->ID;
$file->onAfterUpload();
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
}
示例14: complete
/**
* Completes the job by zipping up the generated export and creating an
* export record for it.
*/
protected function complete()
{
$siteTitle = SiteConfig::current_site_config()->Title;
$filename = preg_replace('/[^a-zA-Z0-9-.+]/', '-', sprintf('%s-%s.zip', $siteTitle, date('c')));
$dir = Folder::findOrMake(SiteExportExtension::EXPORTS_DIR);
$dirname = ASSETS_PATH . '/' . SiteExportExtension::EXPORTS_DIR;
$pathname = "{$dirname}/{$filename}";
SiteExportUtils::zip_directory($this->tempDir, "{$dirname}/{$filename}");
Filesystem::removeFolder($this->tempDir);
$file = new File();
$file->ParentID = $dir->ID;
$file->Title = $siteTitle . ' ' . date('c');
$file->Filename = $dir->Filename . $filename;
$file->write();
$export = new SiteExport();
$export->ParentClass = $this->rootClass;
$export->ParentID = $this->rootId;
$export->Theme = $this->theme;
$export->BaseUrlType = ucfirst($this->baseUrlType);
$export->BaseUrl = $this->baseUrl;
$export->ArchiveID = $file->ID;
$export->write();
if ($this->email) {
$email = new Email();
$email->setTo($this->email);
$email->setTemplate('SiteExportCompleteEmail');
$email->setSubject(sprintf('Site Export For "%s" Complete', $siteTitle));
$email->populateTemplate(array('SiteTitle' => $siteTitle, 'Link' => $file->getAbsoluteURL()));
$email->send();
}
}
示例15: disableOldClientHook
public function disableOldClientHook()
{
// disable the repo client
$reset = false;
$activeModules = $this->Config->getActiveModules();
$inactiveModules = deserialize($GLOBALS['TL_CONFIG']['inactiveModules']);
if (in_array('rep_base', $activeModules)) {
$inactiveModules[] = 'rep_base';
$reset = true;
}
if (in_array('rep_client', $activeModules)) {
$inactiveModules[] = 'rep_client';
$reset = true;
}
if (in_array('repository', $activeModules)) {
$inactiveModules[] = 'repository';
$skipFile = new \File('system/modules/repository/.skip');
$skipFile->write('Remove this file to enable the module');
$skipFile->close();
$reset = true;
}
if ($reset) {
$this->Config->update("\$GLOBALS['TL_CONFIG']['inactiveModules']", serialize($inactiveModules));
$this->reload();
}
unset($GLOBALS['TL_HOOK']['loadLanguageFiles']['composer']);
}