本文整理汇总了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);
}
示例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;
}
示例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();
}
}
}
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例14: moveUploadedFile
public function moveUploadedFile($file, $destFile)
{
$file = new File($file);
if ($file->exists()) {
return $file->copy($destFile);
}
return false;
}
示例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;
}