public function actionCopy()
{
$json = array();
if (isset($_POST['path']) && isset($_POST['name'])) {
if (strlen($_POST['name']) < 3 || strlen($_POST['name']) > 255) {
$json['error'] = Yii::t('filemanager', 'Warning: Filename must be a between 3 and 255!');
}
$old_name = rtrim(Yii::app()->params['imagePath'] . 'data/' . str_replace('../', '', html_entity_decode($_POST['path'], ENT_QUOTES, 'UTF-8')), '/');
if (!file_exists($old_name) || $old_name == Yii::app()->params['imagePath'] . 'data') {
$json['error'] = Yii::t('filemanager', 'Warning: Can not copy this file or directory!');
}
if (is_file($old_name)) {
$ext = strrchr($old_name, '.');
} else {
$ext = '';
}
$new_name = dirname($old_name) . '/' . str_replace('../', '', html_entity_decode($_POST['name'], ENT_QUOTES, 'UTF-8') . $ext);
if (file_exists($new_name)) {
$json['error'] = Yii::t('filemanager', 'Warning: A file or directory with the same name already exists!');
}
} else {
$json['error'] = Yii::t('filemanager', 'Warning: Please select a directory or file!');
}
// TODO: check permissions
/*if (!$this->user->hasPermission('modify', 'common/filemanager')) {
$json['error'] = Yii::t('filemanager', 'Warning: Permission Denied!');
}*/
if (!isset($json['error'])) {
if (is_file($old_name)) {
copy($old_name, $new_name);
} else {
$this->recursiveCopy($old_name, $new_name);
}
$json['success'] = Yii::t('filemanager', 'Success: Your file or directory has been copied!');
}
echo CJSON::encode($json);
}