FileManagerController::actionRename PHP Method

actionRename() public method

public actionRename ( )
    public function actionRename()
    {
        $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 rename this 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!');
            }
        }
        // TODO: check permissions
        /*if (!$this->user->hasPermission('modify', 'common/filemanager')) {
              $json['error'] = Yii::t('filemanager', 'Warning: Permission Denied!');
          }*/
        if (!isset($json['error'])) {
            rename($old_name, $new_name);
            $json['success'] = Yii::t('filemanager', 'Success: Your file or directory has been renamed!');
        }
        echo CJSON::encode($json);
    }