本文整理汇总了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');
}
示例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();
}
}
示例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());
}
示例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();
}
}
}
示例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']);
}
示例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'));
}
示例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();
}
}
}
}
示例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);
}
示例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']);
}
示例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;
}
示例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()]);
}
示例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);
}
示例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;
}
示例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.');
}
示例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();
}
}