Add ability to delete asset files (#3933)
Fixes: #3925. Credit to @Teranode
This commit is contained in:
parent
2d1a904512
commit
82a38bdfb6
|
|
@ -3,6 +3,7 @@
|
|||
use File;
|
||||
use Lang;
|
||||
use Config;
|
||||
use Request;
|
||||
use Cms\Helpers\File as FileHelper;
|
||||
use October\Rain\Extension\Extendable;
|
||||
use ApplicationException;
|
||||
|
|
@ -207,6 +208,23 @@ class Asset extends Extendable
|
|||
$this->originalFileName = $this->fileName;
|
||||
$this->exists = true;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$fileName = Request::input('fileName');
|
||||
$fullPath = $this->getFilePath($fileName);
|
||||
|
||||
$this->validateFileName($fileName);
|
||||
|
||||
if (File::exists($fullPath)) {
|
||||
if (!@File::delete($fullPath)) {
|
||||
throw new ApplicationException(Lang::get(
|
||||
'cms::lang.asset.error_deleting_file',
|
||||
['name' => $fileName]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the supplied filename, extension and path.
|
||||
|
|
|
|||
Loading…
Reference in New Issue