public function folder()
{
$this->load->language('common/filemanager');
$json = array();
// Check user has permission
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
$json['error'] = $this->language->get('error_permission');
}
// Make sure we have the correct directory
if (isset($this->request->get['directory'])) {
$directory = rtrim(DIR_IMAGE . 'catalog/' . $this->request->get['directory'], '/');
} else {
$directory = DIR_IMAGE . 'catalog';
}
// Check its a directory
if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)), 0, strlen(DIR_IMAGE . 'catalog')) != DIR_IMAGE . 'catalog') {
$json['error'] = $this->language->get('error_directory');
}
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
// Sanitize the folder name
$folder = basename(html_entity_decode($this->request->post['folder'], ENT_QUOTES, 'UTF-8'));
// Validate the filename length
if (utf8_strlen($folder) < 3 || utf8_strlen($folder) > 128) {
$json['error'] = $this->language->get('error_folder');
}
// Check if directory already exists or not
if (is_dir($directory . '/' . $folder)) {
$json['error'] = $this->language->get('error_exists');
}
}
if (!isset($json['error'])) {
mkdir($directory . '/' . $folder, 0777);
chmod($directory . '/' . $folder, 0777);
@touch($directory . '/' . $folder . '/' . 'index.html');
$json['success'] = $this->language->get('text_directory');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}