当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem\File类代码示例

本文整理汇总了PHP中Cake\Filesystem\File的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: main

 /**
  * main
  *
  */
 public function main()
 {
     $default = APP . 'Locale' . DS . 'default.pot';
     $response = $this->in("What is the full path you would like to merge file (created pot file)?\nExample:" . $default . "\n[Q]uit", null, $default);
     if (strtoupper($response) === 'Q') {
         $this->out('Merge Aborted');
         $this->_stop();
     }
     $created = new File($response, false, 0755);
     if (!$created->exists()) {
         $this->err('The file path you supplied was not found. Please try again.');
         $this->_stop();
     }
     $default = APP . 'Locale' . DS . 'ja' . DS . 'default.po';
     $response = $this->in("What is the full path you would like to merge file (current po file)?\nExample: " . $default . "\n[Q]uit", null, $default);
     if (strtoupper($response) === 'Q') {
         $this->out('Merge Aborted');
         $this->_stop();
     }
     $current = new File($response, false, 0755);
     if (!$current->exists()) {
         $this->err('The file path you supplied was not found. Please try again.');
         $this->_stop();
     }
     $createdTranslations = Translations::fromPoFile($created->path);
     $createdTranslations->addFromPoFile($current->path);
     $merged = $createdTranslations->toPoString();
     $this->createFile($current->path, $merged);
 }
开发者ID:k1low,项目名称:exec,代码行数:33,代码来源:MergeTask.php

示例2: download

 /**
  * Download an attachment realated to an article.
  *
  * @throws \Cake\Network\Exception\NotFoundException When it missing an arguments or when the file doesn't exist.
  * @throws \Cake\Network\Exception\ForbiddenException When the user is not premium.
  *
  * @return \Cake\Network\Exception\ForbiddenException
  *         \Cake\Network\Exception\NotFoundException
  *         \Cake\Network\Response
  */
 public function download()
 {
     $this->loadModel('Users');
     $user = $this->Users->find()->where(['id' => $this->request->session()->read('Auth.User.id')])->first();
     if (is_null($user) || !$user->premium) {
         throw new ForbiddenException();
     }
     if (!isset($this->request->type)) {
         throw new NotFoundException();
     }
     switch ($this->request->type) {
         case "blog":
             $this->loadModel('BlogAttachments');
             $attachment = $this->BlogAttachments->get($this->request->id);
             if (!$attachment) {
                 throw new NotFoundException();
             }
             $file = new File($attachment->url);
             if (!$file->exists()) {
                 throw new NotFoundException();
             }
             $this->response->file($file->path, ['download' => true, 'name' => $attachment->name]);
             $this->BlogAttachments->patchEntity($attachment, ['download' => $attachment->download + 1]);
             $this->BlogAttachments->save($attachment);
             break;
         default:
             throw new NotFoundException();
     }
     return $this->response;
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:40,代码来源:AttachmentsController.php

示例3: afterDelete

 public function afterDelete(Event $event, Banner $banner, \ArrayObject $options)
 {
     $bannerFile = new File(WWW_ROOT . 'img' . DS . $banner->image);
     $bannerFile->delete();
     $bannerFile->close();
     Cache::clear(false, 'banners_manager_cache');
 }
开发者ID:mswagencia,项目名称:banners-manager,代码行数:7,代码来源:BannersTable.php

示例4: setUp

 /**
  * Cria um plugin de teste e o carrega para conseguir rodar os testes.
  */
 public function setUp()
 {
     parent::setUp();
     $testData = ['full_path' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS, 'config_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'config' . DS, 'css_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'css' . DS, 'js_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'js' . DS, 'img_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'img' . DS, 'packages_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'packages' . DS];
     $pluginFolder = new Folder($testData['full_path'], self::CREATE_FOLDER_IF_NOT_EXISTS, self::PLUGIN_FOLDER_PERMISSIONS);
     $pluginFolder->create($testData['config_folder']);
     $pluginFolder->create($testData['css_folder']);
     $pluginFolder->create($testData['js_folder']);
     $pluginFolder->create($testData['img_folder']);
     $pluginFolder->create($testData['packages_folder'] . 'sample_package');
     $defaultSettingsFile = new File($testData['config_folder'] . 'default_settings.php', true);
     $defaultSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.ThemeInstallerTest.Settings' => \n\t\t\t\t\t['Default' => true]\n\t\t\t\t]; \n\t\t?>");
     $defaultSettingsFile->close();
     $file = new File($testData['css_folder'] . 'sample.css', true);
     $file->write('#id { }');
     $file->close();
     $file = new File($testData['js_folder'] . 'sample.js', true);
     $file->write('#id { }');
     $file->close();
     $file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.css', true);
     $file->write('#id { }');
     $file->close();
     $file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.js', true);
     $file->write('#id { }');
     $file->close();
     $bootstrapFile = new File($testData['config_folder'] . 'bootstrap.php', true);
     $bootstrapFile->close();
 }
开发者ID:mswagencia,项目名称:msw-appcore,代码行数:31,代码来源:ThemeInstallerTest.php

示例5: afterDelete

 public function afterDelete(Event $event, PhotoThumbnail $photo, \ArrayObject $config)
 {
     if (!empty($photo->path)) {
         $file = new File(WWW_ROOT . 'img' . DS . $photo->path);
         $file->delete();
         $file->close();
     }
 }
开发者ID:mswagencia,项目名称:photo-gallery,代码行数:8,代码来源:PhotosThumbnailsTable.php

示例6: removeAndCreateFolder

 private function removeAndCreateFolder($path)
 {
     $dir = new Folder($path);
     $dir->delete();
     $dir->create($path);
     $file = new File($path . DS . 'empty');
     $file->create();
 }
开发者ID:Jurrieb,项目名称:Eendagdeals,代码行数:8,代码来源:CacheShell.php

示例7: writeSwaggerDocumentToFile

 /**
  * Write swagger document to filesystem.
  *
  * @param string $path Full path to the json document including filename
  * @param string $content Swagger content
  * @throws Cake\Network\Exception\InternalErrorException
  * @return bool
  */
 protected static function writeSwaggerDocumentToFile($path, $content)
 {
     $fh = new File($path, true);
     if (!$fh->write($content)) {
         throw new InternalErrorException('Error writing Swagger json document to filesystem');
     }
     return true;
 }
开发者ID:alt3,项目名称:cakephp-swagger,代码行数:16,代码来源:SwaggerTools.php

示例8: _write

 /**
  * Write data in json file.
  *
  * @return void
  */
 protected function _write()
 {
     $this->_bufferActivated();
     $this->_bufferLoaded();
     $JSON = new JSON($this->_buffer);
     $file = Path::loadedFolder() . $this->_config['file'];
     $File = new File($file);
     $File->write($JSON->write());
 }
开发者ID:Cheren,项目名称:union,代码行数:14,代码来源:ThemeBehavior.php

示例9: main

 public function main()
 {
     $tick_names_and_values = array();
     $this->authentication();
     $http = new Client();
     $this->loadModel('Stocks');
     $this->loadModel('Devices');
     $token_file = new File("/home/demo/token/token.txt");
     $token = $token_file->read();
     $token_file->close();
     $MyAuthObject = new OAuthObject(array("token_type" => "Bearer", "access_token" => $token));
     $OptionsToast = new WNSNotificationOptions();
     $OptionsToast->SetAuthorization($MyAuthObject);
     $OptionsToast->SetX_WNS_REQUESTFORSTATUS(X_WNS_RequestForStatus::Request);
     $NotifierToast = new WindowsNotificationClass($OptionsToast);
     $OptionsTile = new WNSNotificationOptions();
     $OptionsTile->SetAuthorization($MyAuthObject);
     $OptionsTile->SetX_WNS_REQUESTFORSTATUS(X_WNS_RequestForStatus::Request);
     //NOTE: Set the Tile type
     $OptionsTile->SetX_WNS_TYPE(X_WNS_Type::Tile);
     $NotifierTile = new WindowsNotificationClass($OptionsTile);
     $allStocks = $this->Stocks->find('all')->toArray();
     //$allStocks = $this->Stocks->find('all')->group(['Stocks.device_id'])->toArray();
     //$allStocks = $this->Stocks->Devices->find()->group(['Devices.id'])->toArray();
     Debugger::dump('allStocks: ');
     Debugger::dump($allStocks);
     $allStocksByDeviceId = array();
     for ($i = 0; $i < sizeof($allStocks); $i++) {
         $actualDeviceId = $allStocks[$i]['device_id'];
         $added = false;
         for ($a = 0; $a < sizeof($allStocksByDeviceId); $a++) {
             if ($allStocksByDeviceId[$a]['device_id'] == $actualDeviceId) {
                 $allStocksByDeviceId[$a]['stocks'][] = $allStocks[$i];
                 $added = true;
             }
         }
         if (!$added) {
             $allStocksByDeviceId[] = ['device_id' => $actualDeviceId, 'stocks' => [$allStocks[$i]]];
         }
     }
     Debugger::dump('allStocksByDeviceId: ');
     Debugger::dump($allStocksByDeviceId);
     $someStocks = $this->Stocks->find()->distinct(['tick_name'])->toArray();
     for ($i = 0; $i < sizeof($someStocks); $i++) {
         $response = $http->get('http://download.finance.yahoo.com/d/quotes?f=sl1d1t1v&s=' . $someStocks[$i]['tick_name']);
         $tick_name = explode(",", $response->body())[0];
         $tick_names_and_values[] = [str_replace("\"", "", $tick_name), explode(",", $response->body())[1]];
     }
     Debugger::dump('tick_names_and_values: ');
     Debugger::dump($tick_names_and_values);
     $this->sendAllStocksNotificationsInTileNotifications($NotifierTile, $tick_names_and_values, $allStocksByDeviceId);
     $this->checkMinMaxValuesAndSendToastNotifications($NotifierToast, $tick_names_and_values);
     //$stuff = implode(",", $stuff);
     //$now = Time::now();
     //$this->createFile('/home/demo/files_created_each_minute/'.$now->i18nFormat('yyyy-MM-dd HH:mm:ss').'.txt', $stuff);
 }
开发者ID:luisfilipe46,项目名称:Stock-Exchange-System-Server,代码行数:56,代码来源:FileShell.php

示例10: afterSave

 public function afterSave(Event $event, Entity $site, \ArrayObject $options)
 {
     $sitePath = WWW_ROOT . '..' . DS . self::SITES_DIR . DS . 'site' . $site->id;
     $folder = new Folder();
     if (!$folder->create($sitePath, 0755)) {
         throw new InternalErrorException('Error create site files');
     }
     $indexHtml = new File($sitePath . DS . 'index.html', true, 0644);
     $indexHtml->write($site->content);
 }
开发者ID:polushin,项目名称:site-manager,代码行数:10,代码来源:SitesTable.php

示例11: del

 public function del()
 {
     if ($this->request->is('ajax')) {
         $data = $this->request->data;
         $foto = $this->CategoriasFotos->findById($data['id'])->first();
         if ($this->CategoriasFotos->delete($foto)) {
             $url = str_replace('../', '', $foto->url);
             $ft = new File($url);
             $ft->delete();
         }
     }
 }
开发者ID:luizhenriquesoares,项目名称:actuale,代码行数:12,代码来源:CategoriasFotosController.php

示例12: uploadToControllerFolderAndIdFolder

 public function uploadToControllerFolderAndIdFolder($file, $controller, $model, $id)
 {
     $filefolder = '../webroot' . DS . 'files';
     $tmppath = AMUploadBehavior::checkIfSubfolderExistsAndCreateIfFalseAndReturnPath($filefolder, $controller);
     $path = AMUploadBehavior::checkIfSubfolderExistsAndCreateIfFalseAndReturnPath($tmppath, $id);
     $filename = $file['name'];
     $tmpfile = new File($file['tmp_name']);
     $fullpath = $path . DS . $filename;
     $tmpfile->copy($fullpath);
     $tmpfile->close();
     return $fullpath;
 }
开发者ID:alexdd55,项目名称:AMUploadBehavior,代码行数:12,代码来源:AMUploadBehavior.php

示例13: write

 /**
  * write serialize data.
  * @param bool $overwrite
  * @return bool
  */
 public function write($overwrite = false)
 {
     $path = $this->getPath();
     if (true === $this->writable() && false === $overwrite) {
         throw new ExistsFileException('exists ' . $path);
     }
     $file = new File($path);
     if (!$file->write($this->export())) {
         throw new \RuntimeException('save failed ' . $path);
     }
     return true;
 }
开发者ID:Rmtram,项目名称:TextDatabase,代码行数:17,代码来源:AbstractWriter.php

示例14: startCaching

 /**
  * startCaching method
  *
  * Cache\[optimize] images in cache folder
  *
  * @param string $optimization 'true' or 'false'
  * @param string $srcPath folder name for source images
  * @return void
  */
 public function startCaching($optimization = 'true', $srcPath = 'src_images')
 {
     $dir = new Folder(WWW_ROOT . 'img' . DS . $srcPath);
     $files = $dir->findRecursive('.*\\.(jpg|jpeg|png|gif|svg)');
     /*
      * Error handler
      */
     if (is_null($dir->path)) {
         $this->error('<red_text>Source folder not exists!</red_text>');
     }
     if ($optimization != 'true' && $optimization != 'false') {
         $this->error('<red_text>Arguments \'optimization\' should equal \'true\' or \'false\'</red_text>');
     }
     /*
      * Caching
      */
     $counter = 1;
     $countFiles = count($files);
     $this->out('<info>Images caching</info>');
     foreach ($files as $file) {
         $file = new File($file);
         $semanticType = explode(DS, $file->Folder()->path);
         $semanticType = $semanticType[count($semanticType) - 1];
         //get semantic type name
         $this->adaptiveImagesController->passiveCaching($file->path, $semanticType);
         $this->_io->overwrite($this->progressBar($counter, $countFiles), 0, 50);
         $counter++;
     }
     /*
      * Optimization
      */
     if ($optimization == 'true') {
         $cachePath = $this->adaptiveImagesController->getCachePath();
         $pluginPath = Plugin::path('AdaptiveImages');
         $cacheDir = new Folder($pluginPath . 'webroot' . DS . $cachePath);
         $files = $cacheDir->findRecursive('.*\\.(jpg|jpeg|png|gif|svg)');
         $counter = 1;
         $countFiles = count($files);
         $this->out('');
         $this->out('<info>Images optimization</info>');
         foreach ($files as $file) {
             $this->_optimizeImage($file);
             $this->_io->overwrite($this->progressBar($counter, $countFiles), 0, 50);
             $counter++;
         }
         $this->hr();
         $this->out('<green_text>Caching and optimization completed!</green_text>');
     } elseif ($optimization == 'false') {
         $this->hr();
         $this->out('<green_text>Caching completed!</green_text>');
     }
 }
开发者ID:e2e4gu,项目名称:adaptive-image-plugin,代码行数:61,代码来源:CacheImagesShell.php

示例15: deleteFile

 /**
  * Delete file action.
  *
  * @return \Cake\Network\Response|void
  */
 public function deleteFile()
 {
     $path = $this->request->query('path');
     if ($this->request->is('post') && is_file($path)) {
         $File = new File($path);
         if ($File->delete()) {
             $this->Flash->success(__d('file_manager', 'File successfully removed'));
         } else {
             $this->Flash->success(__d('file_manager', 'An error occurred while removing a file'));
         }
     }
     return $this->redirect(['action' => 'browse']);
 }
开发者ID:Cheren,项目名称:union,代码行数:18,代码来源:ManagerController.php


注:本文中的Cake\Filesystem\File类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。