当前位置: 首页>>代码示例>>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;未经允许,请勿转载。