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


PHP File::delete方法代碼示例

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


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

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

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

示例3: delete

 public function delete($system, $path)
 {
     $path = str_replace('___', '/', $path);
     $file = new File('../../' . $system . $path);
     if ($file->delete()) {
         $this->Flash->success(__('File removed successfully.'));
     } else {
         $this->Flash->error(__('Unable remove file.'));
     }
     return $this->redirect($this->referer());
 }
開發者ID:jaambageek,項目名稱:cakeboot-template,代碼行數:11,代碼來源:FilesController.php

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

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

示例6: delete

 /**
  * Deletes a file for the given FileField instance.
  *
  * File name must be passes as `file` GET parameter.
  *
  * @param string $name EAV attribute name
  * @return void
  * @throws \Cake\Network\Exception\NotFoundException When invalid attribute name
  *  is given
  */
 public function delete($name)
 {
     $this->loadModel('Field.FieldInstances');
     $instance = $this->_getInstance($name);
     if ($instance && !empty($this->request->query['file'])) {
         $file = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/{$this->request->query['file']}", DS);
         $file = new File($file);
         $file->delete();
     }
     $response = '';
     $this->viewBuilder()->layout('ajax');
     $this->title(__d('field', 'Delete File'));
     $this->set(compact('response'));
 }
開發者ID:quickapps-plugins,項目名稱:field,代碼行數:24,代碼來源:FileHandlerController.php

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

示例8: testShrinkJs

 /**
  * Test that js files are properly processed
  *
  * @return void
  */
 public function testShrinkJs()
 {
     $ret = $this->Shrink->build(['base.js', 'base.coffee'], 'js');
     // verify the result has the proper keys
     $this->assertArrayHasKey('path', $ret);
     $this->assertArrayHasKey('webPath', $ret);
     // verify we were returned a file
     $this->assertFileExists($ret['path']);
     // verify the contents
     $cacheFile = new File($ret['path']);
     $result = $cacheFile->read();
     $cacheFile->delete();
     $cacheFile->close();
     $expectedfile = new File(WWW_ROOT . 'js/base.shrink.js');
     $expect = $expectedfile->read();
     $expectedfile->close();
     $this->assertEquals($expect, $result);
 }
開發者ID:edukondaluetg,項目名稱:cakephp-shrink,代碼行數:23,代碼來源:ShrinkTest.php

示例9: delete

 public function delete($id = null)
 {
     $this->request->allowMethod(['post', 'delete']);
     $conteudo = $this->Conteudos->get($id);
     $this->loadModel('ConteudosFotos');
     $fotos = $this->ConteudosFotos->findAllByConteudoId($id);
     foreach ($fotos as $foto) {
         $url = str_replace('../', '', $foto->url);
         $file = new File($url);
         if ($file->delete()) {
             $this->ConteudosFotos->delete($foto);
         }
     }
     if ($this->Conteudos->delete($conteudo)) {
         $this->Flash->success(__('Conteúdo deletado!'));
     } else {
         $this->Flash->error(__('Ops... Algo de errado aconteceu, por favor, tente novamente!'));
     }
     return $this->redirect(['action' => 'index']);
 }
開發者ID:luizhenriquesoares,項目名稱:actuale,代碼行數:20,代碼來源:ConteudosController.php

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

示例11: edit

 /**
  *  Image manipulation view - Includes a small toolbox for basic
  *  image editing before saving or discarding changes
  */
 public function edit($id, $action = null, array $params = null)
 {
     $image = $this->Images->get($id, ['contain' => 'Uploads']);
     if ($this->request->is(['post', 'put'])) {
         $imgFile = new File($image->upload->full_path);
         // Backup original
         $backupFile = new File(TMP . DS . time() . 'bak');
         $imgFile->copy($backupFile->path);
         if (!$image->hasTmp()) {
             return $this->Flash->error('Sorry, we lost your edit...');
         }
         // Open tmp file
         $tmpFile = new File($image->tmp_path_full);
         // Copy tmp file to permanent location
         if (!$tmpFile->copy($imgFile->path)) {
             return $this->Flash->error('Could not save image');
         }
         // Change recorded image dimentions and size
         $image->upload->size = $tmpFile->size();
         $image->width = $this->Image->width($tmpFile->path);
         $image->height = $this->Image->height($tmpFile->path);
         // Delete tmp file
         $image->deleteTmp();
         if (!$this->Images->save($image)) {
             // Restore file with matching, original size and dimentions
             $backupFile->copy($imgFile->path);
             $backupFile->delete();
             $this->Flash->error('Could not save image.');
             return $this->redirect();
         } else {
             $this->Flash->success('Image edited successfully.');
             return $this->redirect();
         }
     } else {
         if (!$image->hasTmp()) {
             $image->makeTmp();
         }
     }
     $this->set(['image' => $image, 'route' => $this->RedirectUrl->load()]);
 }
開發者ID:propellerstudios,項目名稱:UploadManager,代碼行數:44,代碼來源:ImagesController.php

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

示例13: upload

 /**
  * Uploads a ZIP package to the server.
  *
  * @return bool True on success
  */
 public function upload()
 {
     if (!isset($this->_package['tmp_name']) || !is_readable($this->_package['tmp_name'])) {
         $this->_error(__d('installer', 'Invalid package.'));
         return false;
     } elseif (!isset($this->_package['name']) || !str_ends_with(strtolower($this->_package['name']), '.zip')) {
         $this->_error(__d('installer', 'Invalid package format, it is not a ZIP package.'));
         return false;
     } else {
         $dst = normalizePath(TMP . $this->_package['name']);
         if (is_readable($dst)) {
             $file = new File($dst);
             $file->delete();
         }
         if (move_uploaded_file($this->_package['tmp_name'], $dst)) {
             $this->_dst = $dst;
             return true;
         }
     }
     $this->_error(__d('installer', 'Package could not be uploaded, please check write permissions on /tmp directory.'));
     return false;
 }
開發者ID:quickapps-plugins,項目名稱:installer,代碼行數:27,代碼來源:PackageUploader.php

示例14: main

 /**
  * main method
  *
  * @param  string $tempDir an other directory to clear of all folders and files, if desired
  * @return void
  */
 public function main($tempDir = null)
 {
     if (empty($tempDir)) {
         $tempDir = Configure::read('Attachments.tmpUploadsPath');
     }
     if (!Folder::isAbsolute($tempDir)) {
         $this->out('The path must be absolute, "' . $tempDir . '" given.');
         exit;
     }
     $Folder = new Folder();
     if ($Folder->cd($tempDir) === false) {
         $this->out('Path "' . $tempDir . '" doesn\'t seem to exist.');
         exit;
     }
     $dir = new Folder($tempDir);
     $folders = $dir->read();
     $files = $dir->findRecursive();
     $deletedFiles = 0;
     $deletedFolders = 0;
     $this->out('Found ' . count($folders[0]) . ' folders and ' . count($files) . ' files');
     foreach ($files as $filePath) {
         $file = new File($filePath);
         // only delete if last change is longer than 24 hours ago
         if ($file->lastChange() < time() - 24 * 60 * 60 && $file->delete()) {
             $deletedFiles++;
         }
         $file->close();
     }
     foreach ($folders[0] as $folderName) {
         $folder = new Folder($dir->pwd() . $folderName);
         // only delete if folder is empty
         if ($folder->dirsize() === 0 && $folder->delete()) {
             $deletedFolders++;
         }
     }
     $this->out('Deleted ' . $deletedFolders . ' folders and ' . $deletedFiles . ' files.');
 }
開發者ID:cleptric,項目名稱:cake-attachments,代碼行數:43,代碼來源:CleanTempShell.php

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


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