public function actionDelete()
{
$json = array();
if (isset($_POST['path'])) {
$path = rtrim(Yii::app()->params['imagePath'] . 'data/' . str_replace('../', '', html_entity_decode($_POST['path'], ENT_QUOTES, 'UTF-8')), '/');
if (!file_exists($path)) {
$json['error'] = Yii::t('filemanager', 'Warning: Please select a directory or file!');
}
if ($path == rtrim(Yii::app()->params['imagePath'] . 'data/', '/')) {
$json['error'] = Yii::t('filemanager', 'Warning: You can not delete this directory!');
}
} else {
$json['error'] = Yii::t('filemanager', 'Warning: Please select a directory or file!');
}
// TODO: check permission
/*if (!$this->user->hasPermission('modify', 'common/filemanager')) {
$json['error'] = Yii::t('filemanager', 'Warning: Permission Denied!');
}*/
if (!isset($json['error'])) {
if (is_file($path)) {
unlink($path);
} elseif (is_dir($path)) {
$files = array();
$path = array($path . '*');
while (count($path) != 0) {
$next = array_shift($path);
foreach (glob($next) as $file) {
if (is_dir($file)) {
$path[] = $file . '/*';
}
$files[] = $file;
}
}
rsort($files);
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
} elseif (is_dir($file)) {
rmdir($file);
}
}
}
$json['success'] = Yii::t('filemanager', 'Success: Your file or directory has been deleted!');
}
echo CJSON::encode($json);
}