OpenCart 🇺🇦

Схема

public mixed delete ( )

Аргументы

Аргумент Возможный тип Описание
У метода нет аргументов

Описание

Метод пока еще не документирован.

Исходный код

$this->language->load('common/filemanager');

$json = array();

if (isset($this->request->post['path'])) {
	$path = rtrim(DIR_IMAGE . 'data/' . str_replace('../', '', html_entity_decode($this->request->post['path'], ENT_QUOTES, 'UTF-8')), '/');

	if (!file_exists($path)) {
		$json['error'] = $this->language->get('error_select');
	}

	if ($path == rtrim(DIR_IMAGE . 'data/', '/')) {
		$json['error'] = $this->language->get('error_delete');
	}
} else {
	$json['error'] = $this->language->get('error_select');
}

if (!$this->user->hasPermission('modify', 'common/filemanager')) {
	$json['error'] = $this->language->get('error_permission');
}

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'] = $this->language->get('text_delete');
}

$this->response->setOutput(json_encode($json));