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


PHP File::exists方法代码示例

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


在下文中一共展示了File::exists方法的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, Entity $entity, $options)
 {
     $config = $this->_config;
     foreach ($config['fields'] as $field) {
         $entityField = $entity->get($field);
         if (!empty($entityField)) {
             $filePath = $config['root'] . $entityField;
             $file = new File($filePath, false, 755);
             if ($file->exists() === true) {
                 $file->delete();
             }
         }
     }
 }
开发者ID:quicake,项目名称:files,代码行数:14,代码来源:DeleteBehavior.php

示例4: load

 /**
  * Load a YAML configuration file
  * located in ROOT/config/yaml/FILENAME
  *
  * We can use it like this:
  *      LoaderComponent::load('FILENAME.yml')
  *
  * @uses Cake\Filesystem\File
  * @param string The file name, extend with .yml
  * @param string The callback filename, if the first name parameter file doesn't exist, looking for the callback file
  * @throws \Exception
  * @return array The yaml data in array format
  */
 public static function load($file, $callback = null)
 {
     $path = ROOT . DS . 'config' . DS . 'yaml' . DS . $file;
     $oFile = new File($path);
     if (!$oFile->exists()) {
         if (is_null($callback)) {
             throw new Exception($path . " doesn't exists!!");
         } else {
             return static::load($callback);
         }
     }
     if (in_array($file, array_keys(static::$_loadedConfig))) {
         $config = static::$_loadedConfig[$file];
     } else {
         $config = Yaml::parse($oFile->read());
         static::$_loadedConfig[$file] = $config;
     }
     return $config;
 }
开发者ID:EdouardTack,项目名称:loaderyaml,代码行数:32,代码来源:LoaderComponent.php

示例5: deleteFile

 private function deleteFile(Attachment $attachment, $recursive = false)
 {
     $return = true;
     $dir = new Folder(Configure::read('Upload.path') . $attachment->get('file_path'));
     if ($recursive) {
         $files = $dir->findRecursive($attachment->get('file_name') . '.*', true);
     } else {
         $files = $dir->find($attachment->get('file_name') . '.*');
     }
     foreach ($files as $file) {
         $fileTmp = new File($file);
         if ($fileTmp->exists()) {
             if (!$fileTmp->delete()) {
                 $return = false;
             }
         } else {
             $return = false;
         }
     }
     return $return;
 }
开发者ID:grandfelix,项目名称:woodyattachments,代码行数:21,代码来源:AttachmentsTable.php

示例6: select2GetImage

 /**
  * select2GetImage method
  *
  * @return void
  */
 public function select2GetImage($table, $id, $imageSrcCol = null)
 {
     if (!$this->request->is('ajax')) {
         return;
     }
     $this->autoRender = false;
     $this->viewBuilder()->layout('ajax');
     $this->loadModel($table);
     $q = $this->{$table}->find('all')->where(["{$table}.id" => $id]);
     //if image not exists
     if (!is_null($imageSrcCol) && $imageSrcCol != 'undefined') {
         $pluginPath = Plugin::path('LightStrap');
         foreach ($q as $item) {
             $imageFile = new File(WWW_ROOT . 'files' . DS . $item->{$imageSrcCol});
             if (!$imageFile->exists()) {
                 $item->path = '../light_strap/img/no_image.png';
             }
         }
     }
     echo json_encode($q->toArray());
 }
开发者ID:e2e4gu,项目名称:cakeadmin-lightstrap,代码行数:26,代码来源:AjaxController.php

示例7: testShrinkJs

 /**
  * test that js files are properly queued and processed
  *
  * @return void
  */
 public function testShrinkJs()
 {
     $this->Shrink->js(['base.js', 'base.coffee']);
     $tag = $this->Shrink->fetch('js');
     // did it create a link tag?
     $this->assertRegExp('/^\\<script\\s/', $tag);
     // grab the url if it has one (it always should)
     preg_match('/src="(?P<url>.+?)"/', $tag, $matches);
     $this->assertArrayHasKey('url', $matches);
     // verify the file exists
     $url = $matches['url'];
     $file = new File(WWW_ROOT . $url);
     $this->assertTrue($file->exists());
     // verify the contents
     $result = $file->read();
     $file->delete();
     $file->close();
     $expectedfile = new File(WWW_ROOT . 'js/base.shrink.js');
     $expect = $expectedfile->read();
     $expectedfile->close();
     $this->assertEquals($expect, $result);
 }
开发者ID:edukondaluetg,项目名称:cakephp-shrink,代码行数:27,代码来源:ShrinkHelperTest.php

示例8: hasTmp

 /**
  *  Check to see if a temporary file for this entity's original
  *  file exists.
  *
  *  @return boolean Success
  */
 public function hasTmp()
 {
     $tmp = new File($this->tmpPathFull);
     return $tmp->exists();
 }
开发者ID:propellerstudios,项目名称:UploadManager,代码行数:11,代码来源:Image.php

示例9: _deleteOldUpload

 /**
  * Delete the old upload file before to save the new file.
  *
  * We can not just rely on the copy file with the overwrite, because if you use
  * an identifier like :md5 (Who use a different name for each file), the copy
  * function will not delete the old file.
  *
  * @param \Cake\ORM\Entity $entity  The entity that is going to be saved.
  * @param bool|string      $field   The current field to process.
  * @param bool|string      $newFile The new file path.
  * @param array            $options The configuration options defined by the user.
  *
  * @return bool
  */
 protected function _deleteOldUpload(Entity $entity, $field = false, $newFile = false, array $options = [])
 {
     if ($field === false || $newFile === false) {
         return true;
     }
     $fileInfo = pathinfo($entity->{$field});
     $newFileInfo = pathinfo($newFile);
     if (isset($options['defaultFile']) && (is_bool($options['defaultFile']) || is_string($options['defaultFile']))) {
         $this->_defaultFile = $options['defaultFile'];
     }
     if ($fileInfo['basename'] == $newFileInfo['basename'] || $fileInfo['basename'] == pathinfo($this->_defaultFile)['basename']) {
         return true;
     }
     if ($this->_prefix) {
         $entity->{$field} = str_replace($this->_prefix, "", $entity->{$field});
     }
     $file = new File($this->_config['root'] . $entity->{$field}, false);
     if ($file->exists()) {
         $file->delete();
         return true;
     }
     return false;
 }
开发者ID:MillHidden,项目名称:BiellesMeusiennes,代码行数:37,代码来源:UploadBehavior.php

示例10: modelExist

 /**
  * To check if a Table Model exists in the path of model
  *
  * @param string $tableName Table name in underscore case
  * @param string $pluginName Plugin name if exists
  * @return bool
  */
 public function modelExist($tableName, $pluginName = null)
 {
     $file = new File($this->getModelPath($pluginName) . $tableName . 'Table.php');
     if ($file->exists()) {
         return true;
     }
     return false;
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:15,代码来源:MigrationTask.php

示例11: _removeFile

 /**
  * _removeFile
  *
  * @param string $file Path of the file
  * @return bool
  */
 protected function _removeFile($file)
 {
     $_file = new File($file);
     if ($_file->exists()) {
         $_file->delete();
         $folder = $_file->folder();
         if (count($folder->find()) === 0) {
             $folder->delete();
         }
         return true;
     }
     return false;
 }
开发者ID:eAliwei,项目名称:cakephp-utils,代码行数:19,代码来源:UploadableBehavior.php

示例12: deleteOldUpload

 /**
  * Delete the old upload file before to save the new file.
  *
  * We can not just rely on the copy file with the overwrite, because if you use
  * an identifier like :md5 (Who use a different name for each file), the copy
  * function will not delete the old file.
  *
  * @param \Cake\ORM\Entity $entity  The entity that is going to be saved.
  * @param string           $field   The current field to process.
  * @param array            $options The configuration options defined by the user.
  * @param string           $newFile The new file path.
  *
  * @return bool
  */
 private function deleteOldUpload(Entity $entity, $field = '', array $options = [], $newFile)
 {
     $fileInfo = pathinfo($entity->{$field});
     $newFileInfo = pathinfo($newFile);
     /**
      * Check if the user has set an option for the defaultFile, else use the default defaultFile config.
      */
     if (isset($options['defaultFile']) && (is_bool($options['defaultFile']) || is_string($options['defaultFile']))) {
         $this->_defaultFile = $options['defaultFile'];
     }
     /**
      * If the old file have the same name as the new file, let the copy
      * function do the overwrite.
      *
      * Or if the old file have the same name as the defaultFile, do not delete it.
      * For example, if you use a default_avatar.png for all new members, this condition
      * will make sure that the default_avatar.png will not be deleted.
      *
      */
     if ($fileInfo['basename'] == $newFileInfo['basename'] || $fileInfo['basename'] == $this->_defaultFile) {
         return true;
     }
     if ($this->_prefix) {
         /**
          * Replace the prefix. This is useful when you use a custom directory at the root
          * of webroot and you use the Html Helper to display your image.
          *
          * (Because the Html Helper is pointed to the img/ directory by default)
          */
         $entity->{$field} = str_replace($this->_prefix, "", $entity->{$field});
     }
     /**
      * Instance the File.
      */
     $file = new File($entity->{$field}, false);
     /**
      * If the file exist, than delete it.
      */
     if ($file->exists()) {
         $file->delete();
         return true;
     }
     return false;
 }
开发者ID:luizhenriquesoares,项目名称:actuale,代码行数:58,代码来源:UploadBehavior.php

示例13: tableExists

 /**
  * To check if a Table Model exists in the path of model
  *
  * @param string $tableName Table name in underscore case
  * @param string $pluginName Plugin name if exists
  * @return bool
  */
 public function tableExists($tableName, $pluginName = null)
 {
     $file = new File($this->getModelPath($pluginName) . $tableName . 'Table.php');
     return $file->exists();
 }
开发者ID:RogerSchmeier,项目名称:Webtruck,代码行数:12,代码来源:MigrationSnapshotTask.php

示例14: moveUploadedFile

 public function moveUploadedFile($file, $destFile)
 {
     $file = new File($file);
     if ($file->exists()) {
         return $file->copy($destFile);
     }
     return false;
 }
开发者ID:xenolOnline,项目名称:resumable.php,代码行数:8,代码来源:Resumable.php

示例15: createFile

 /**
  * Creates a file at given path
  *
  * @param string $path Where to put the file.
  * @param string $contents Content to put in the file.
  * @return bool Success
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#creating-files
  */
 public function createFile($path, $contents)
 {
     $path = str_replace(DS . DS, DS, $path);
     $this->_io->out();
     if (is_file($path) && empty($this->params['force']) && $this->interactive) {
         $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
         $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n');
         if (strtolower($key) === 'q') {
             $this->_io->out('<error>Quitting</error>.', 2);
             return $this->_stop();
         }
         if (strtolower($key) === 'a') {
             $this->params['force'] = true;
             $key = 'y';
         }
         if (strtolower($key) !== 'y') {
             $this->_io->out(sprintf('Skip `%s`', $path), 2);
             return false;
         }
     } else {
         $this->out(sprintf('Creating file %s', $path));
     }
     $File = new File($path, true);
     if ($File->exists() && $File->writable()) {
         $data = $File->prepare($contents);
         $File->write($data);
         $this->_io->out(sprintf('<success>Wrote</success> `%s`', $path));
         return true;
     }
     $this->_io->err(sprintf('<error>Could not write to `%s`</error>.', $path), 2);
     return false;
 }
开发者ID:a53ali,项目名称:CakePhP,代码行数:40,代码来源:Shell.php


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