-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteAction.php
51 lines (42 loc) · 1.34 KB
/
DeleteAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace makroxyz\fileupload;
use Yii;
class DeleteAction extends BaseAction
{
/**
* @var string temporary upload destination
*/
public $uploadDest;
/**
* @var string thumbnail destination
*/
public $thumbDest;
/**
* @var boolean whether to use thumbs directory
*/
public $useThumbs = true;
public function run($filename)
{
if ($this->uploadDest === null) {
$this->uploadDest = \Yii::$app->runtimePath . DIRECTORY_SEPARATOR . 'temp';
} else {
$this->uploadDest = \Yii::getAlias($this->uploadDest);
}
if ($this->thumbDest === null) {
$this->thumbDest = $this->uploadDest . DIRECTORY_SEPARATOR . 'thumb';
} else {
$this->thumbDest = \Yii::getAlias($this->thumbDest);
}
$filename = $this->cleanFilename($filename);
$path = $this->uploadDest . DIRECTORY_SEPARATOR . $filename;
if (!file_exists($path)) {
throw new \yii\web\NotFoundHttpException();
}
if ($this->useThumbs) {
@unlink($this->thumbDest . DIRECTORY_SEPARATOR . $filename);
}
@unlink($this->uploadDest . DIRECTORY_SEPARATOR . $filename);
Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;
return true;
}
}