當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。