當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::Folder方法代碼示例

本文整理匯總了PHP中Cake\Filesystem\File::Folder方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::Folder方法的具體用法?PHP File::Folder怎麽用?PHP File::Folder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Filesystem\File的用法示例。


在下文中一共展示了File::Folder方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: beforeDelete

 /**
  * Delete file on server represented by entity being deleted
  */
 public function beforeDelete(Event $event, Entity $entity, \ArrayObject $options)
 {
     Configure::load('UploadManager.uploads', 'default');
     $storagePath = Configure::read('Uploads.storagePath');
     $file = new File($entity->path);
     $folder = $file->Folder();
     // Check for empty directories on successful delete
     if ($file->delete()) {
         // Delete type folder if empty
         if (!$folder->find()) {
             $oldFolder = $folder;
             $folder->cd($folder->realpath($folder->pwd() . DS . '..'));
             $oldFolder->delete();
             // Check for other possible empty parent (owner storage)
             if ($folder->pwd() !== $storagePath) {
                 if (!$folder->find()) {
                     $folder->delete();
                 }
             }
         }
     } else {
         $event->stopPropagation();
     }
 }
開發者ID:propellerstudios,項目名稱:UploadManager,代碼行數:27,代碼來源:UploadsTable.php

示例3: delete

 /**
  * Delete an existing file on the server, if this causes
  * the directory to be empty, delete it; provided it is
  * not the root of uploads.
  * 
  * @param path - location of file
  * @return result of delete (success/fail)
  */
 public function delete($path)
 {
     $file = new File($path);
     $folder = $file->Folder();
     // Check for empty directories on successful delete
     if ($file->delete()) {
         // Delete type folder if empty
         if (!$folder->find()) {
             $oldFolder = $folder;
             $folder->cd($folder->realpath($folder->pwd() . DS . '..'));
             $oldFolder->delete();
             // Check for other possible empty parent (owner storage)
             if ($folder->pwd() !== $storagePath) {
                 if (!$folder->find()) {
                     $folder->delete();
                 }
             }
         }
     } else {
         return false;
     }
 }
開發者ID:propellerstudios,項目名稱:UploadManager,代碼行數:30,代碼來源:UploaderComponent.php


注:本文中的Cake\Filesystem\File::Folder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。