本文整理汇总了PHP中File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:niltonfelipe,项目名称:e-cidade_transparencia,代码行数:34,代码来源:check_point.php
示例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));
}
}
}
开发者ID:Erwane,项目名称:cakephp-AssetMinify,代码行数:33,代码来源:AssetMinifyShell.php
示例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');
}
}
开发者ID:morrislaptop,项目名称:settings,代码行数:25,代码来源:TranslationsController.php
示例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);
}
开发者ID:helpfulrobot,项目名称:comperio-silverstripe-cms,代码行数:25,代码来源:SiteTreeBrokenLinksTest.php
示例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;
}
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:39,代码来源:Attachment.class.php
示例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']);
}
}
开发者ID:ruysu,项目名称:laravel-core,代码行数:11,代码来源:FileUploader.php
示例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));
}
开发者ID:ayaou,项目名称:Zuha,代码行数:35,代码来源:Alias.php
示例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;
}
开发者ID:luizgabriel,项目名称:infire,代码行数:7,代码来源:FileUploader.php
示例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));
}
开发者ID:respect,项目名称:validation,代码行数:10,代码来源:FileTest.php
示例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));
}
}
}
开发者ID:predominant,项目名称:candycane,代码行数:34,代码来源:install_controller.php
示例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');
}
开发者ID:kittolau,项目名称:gcm,代码行数:35,代码来源:ThumbnailImageGenerator.php
示例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;
}
}
}
开发者ID:hafriedlander,项目名称:silverstripe-config-experiment,代码行数:26,代码来源:LeftAndMainSubsites.php
示例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);
}
开发者ID:hafriedlander,项目名称:silverstripe-config-experiment,代码行数:31,代码来源:FileSubsitesTest.php
示例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();
}
}
开发者ID:rodneyway,项目名称:silverstripe-siteexporter,代码行数:35,代码来源:SiteExportJob.php
示例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']);
}
开发者ID:tim-bec,项目名称:composer-client,代码行数:27,代码来源:Client.php
示例16: execute
function execute()
{
$file_or_folder = $this->file_or_folder;
if (self::$dummy_mode) {
echo "Adding : " . $file_or_folder . "<br />";
return;
}
$root_dir_path = self::$root_dir->getPath();
$file_or_folder = str_replace("\\", "/", $file_or_folder);
$file_list = array();
//se finisce con lo slash è una directory
if (substr($file_or_folder, strlen($file_or_folder) - 1, 1) == "/") {
//creo la cartella
$target_dir = new Dir(DS . $root_dir_path . $file_or_folder);
$target_dir->touch();
$source_dir = new Dir($this->module_dir->getPath() . $file_or_folder);
foreach ($source_dir->listFiles() as $elem) {
if ($elem->isDir()) {
$file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getName() . DS));
} else {
$file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getFilename()));
}
}
} else {
$source_file = new File($this->module_dir->getPath() . $file_or_folder);
$target_file = new File($root_dir_path . $file_or_folder);
$target_dir = $target_file->getDirectory();
$target_dir->touch();
$source_file->copy($target_dir);
$file_list[] = $target_dir->newFile($source_file->getFilename())->getPath();
}
return $file_list;
}
开发者ID:mbcraft,项目名称:frozen,代码行数:33,代码来源:AddModuleAction.class.php
示例17: getFile
function getFile($fID) {
Loader::model('file');
$mf = new File();
$file_obj = $mf->getByID($fID);
$fileversion_obj = $file_obj->getVersion();
$bf = new LibraryFileBlockController;
$ftype = FileTypeList::getType($fileversion_obj->getExtension());
$this->generictype = strtolower($ftype->getGenericTypeText($ftype->getGenericType()));
$this->filename = $fileversion_obj->getFileName();
$this->type = $fileversion_obj->getType();
$this->url = $fileversion_obj->getURL();
$this->filepath = $fileversion_obj->getPath();
$this->relpath = $fileversion_obj->getRelativePath();
$this->origfilename = $fileversion_obj->getRelativePath();
$this->filesize = $fileversion_obj->getFullSize();
$len = strlen(REL_DIR_FILES_UPLOADED);
$fh = Loader::helper('concrete/file');
$bf->bID = $fileversion_obj->getFileID();
$bf->generictype = $this->generictype;
$bf->type = $this->type;
$bf->url = $this->url;
$bf->filepath = $this->filepath;
$bf->relpath = $this->relpath;
$bf->filename = substr($this->relpath, $len); // for backwards compatibility this must include the prefixes
$bf->filesize = $this->filesize;
return $bf;
}
开发者ID:rii-J,项目名称:concrete5-de,代码行数:32,代码来源:controller.php
示例18: save
public function save()
{
$file = new File();
$file->setFromValidatedFile($this->getValue('file'));
$file->setName(sprintf('admin_%s_%d', $this->getValue('imageName'), time()));
return $file->save();
}
开发者ID:te-koyama,项目名称:openpne,代码行数:7,代码来源:ImageForm.php
示例19: renderContent
/**
* Render a single message content element.
*
* @param RenderMessageContentEvent $event
*
* @return string
*/
public function renderContent(RenderMessageContentEvent $event)
{
global $container;
$content = $event->getMessageContent();
if ($content->getType() != 'downloads' || $event->getRenderedContent()) {
return;
}
/** @var EntityAccessor $entityAccessor */
$entityAccessor = $container['doctrine.orm.entityAccessor'];
$context = $entityAccessor->getProperties($content);
$context['files'] = array();
foreach ($context['downloadSources'] as $index => $downloadSource) {
$context['downloadSources'][$index] = $downloadSource = \Compat::resolveFile($downloadSource);
$file = new \File($downloadSource, true);
if (!$file->exists()) {
unset($context['downloadSources'][$index]);
continue;
}
$context['files'][$index] = array('url' => $downloadSource, 'size' => \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $downloadSource)), 'icon' => 'assets/contao/images/' . $file->icon, 'title' => basename($downloadSource));
}
if (empty($context['files'])) {
return;
}
$template = new \TwigTemplate('avisota/message/renderer/default/mce_downloads', 'html');
$buffer = $template->parse($context);
$event->setRenderedContent($buffer);
}
开发者ID:avisota,项目名称:contao-message-element-downloads,代码行数:34,代码来源:DefaultRenderer.php
示例20: updateFileHeaders
protected function updateFileHeaders(File $file, array $headers)
{
$status = $file->getRepo()->getBackend()->describe(['src' => $file->getPath(), 'headers' => $headers]);
if (!$status->isGood()) {
$this->error("Encountered error: " . print_r($status, true));
}
}
开发者ID:paladox,项目名称:mediawiki,代码行数:7,代码来源:refreshFileHeaders.php
注:本文中的File类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论