2016-05-01 5 views
-1

Wenn nicht, dann der Code in VERÄNDERUNG IN FOLGENDEN: Admin/conroller/common/filemanager.phpOpencart 2.0 IMAGE MANAGER FUNKTIONIERT NICHT

VON Vinay Singh [[email protected]] skype: vinaysingh43

oder Chagne den Code in Zeile keine GLOBAL_BRACE

CONSTANT diese contstant nicht wth einige Server wroking ...

<?php 
 

 
class ControllerCommonFileManager extends Controller { 
 

 
public function index() { 
 

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

 

 

 
if (isset($this->request->get['filter_name'])) { 
 

 
$filter_name = rtrim(str_replace(array('../', '..\\', '..', '*'), '', $this->request->get['filter_name']), '/'); 
 

 
} else { 
 

 
$filter_name = null; 
 

 
} 
 

 

 

 
// Make sure we have the correct directory 
 

 
if (isset($this->request->get['directory'])) { 
 

 
$directory = rtrim(DIR_IMAGE . 'catalog/' . str_replace(array('../', '..\\', '..'), '', $this->request->get['directory']), '/'); 
 

 
} else { 
 

 
$directory = DIR_IMAGE . 'catalog'; 
 

 
} 
 

 

 

 
if (isset($this->request->get['page'])) { 
 

 
$page = $this->request->get['page']; 
 

 
} else { 
 

 
$page = 1; 
 

 
} 
 

 

 

 
$data['images'] = array(); 
 

 

 

 
$this->load->model('tool/image'); 
 

 

 

 
// Get directories 
 

 
$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR); 
 

 

 

 
if (!$directories) { 
 

 
$directories = array(); 
 

 
} 
 

 

 

 
// Get files 
 

 
// $files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE); 
 

 

 

 
$files1 = glob($directory . '/' . $filter_name . '*.jpg'); 
 

 
if (!$files1) { 
 

 
$files1 = array(); 
 

 
} 
 

 

 

 
$files2 = glob($directory . '/' . $filter_name . '*.jpeg'); 
 

 
if (!$files2) { 
 

 
$files2 = array(); 
 

 
} 
 

 

 

 
$files3 = glob($directory . '/' . $filter_name . '*.JPG'); 
 

 
if (!$files3) { 
 

 
$files3 = array(); 
 

 
} 
 

 

 

 
$files4 = glob($directory . '/' . $filter_name . '*.png'); 
 

 
if (!$files4) { 
 

 
$files4 = array(); 
 

 
} 
 

 

 

 
$files5 = glob($directory . '/' . $filter_name . '*.JPEG'); 
 

 
if (!$files5) { 
 

 
$files5 = array(); 
 

 
} 
 

 

 

 
$files6 = glob($directory . '/' . $filter_name . '*.PNG'); 
 

 
if (!$files6) { 
 

 
$files6 = array(); 
 

 
} 
 

 

 

 
$files7 = glob($directory . '/' . $filter_name . '*.GIF'); 
 

 
if (!$files7) { 
 

 
$files7 = array(); 
 

 
} 
 

 
$files8 = glob($directory . '/' . $filter_name . '*.gif'); 
 

 
if (!$files8) { 
 

 
$files8 = array(); 
 

 
} 
 

 

 

 

 

 
$files = array_merge($files1, $files2,$files3,$files4,$files5,$files6,$files7,$files8); 
 

 

 

 

 

 
// Merge directories and files 
 

 
$images = array_merge($directories, $files); 
 

 

 

 
// Get total number of files and directories 
 

 
$image_total = count($images); 
 

 

 

 
// Split the array based on current page number and max number of items per page of 10 
 

 
$images = array_splice($images, ($page - 1) * 16, 16); 
 

 

 

 
foreach ($images as $image) { 
 

 
$name = str_split(basename($image), 14); 
 

 

 

 
if (is_dir($image)) { 
 

 
\t $url = ''; 
 

 

 

 
\t if (isset($this->request->get['target'])) { 
 

 
\t \t \t \t \t $url .= '&target=' . $this->request->get['target']; 
 

 
\t } 
 

 

 

 
\t if (isset($this->request->get['thumb'])) { 
 

 
\t \t \t \t \t $url .= '&thumb=' . $this->request->get['thumb']; 
 

 
\t } 
 

 

 

 
\t $data['images'][] = array(
 

 
\t \t \t \t \t 'thumb' => '', 
 

 
\t \t \t \t \t 'name' => implode(' ', $name), 
 

 
\t \t \t \t \t 'type' => 'directory', 
 

 
\t \t \t \t \t 'path' => utf8_substr($image, utf8_strlen(DIR_IMAGE)), 
 

 
\t \t \t \t \t 'href' => $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . '&directory=' . urlencode(utf8_substr($image, utf8_strlen(DIR_IMAGE . 'catalog/'))) . $url, true) 
 

 
\t); 
 

 
} elseif (is_file($image)) { 
 

 
\t // Find which protocol to use to pass the full image link back 
 

 
\t if ($this->request->server['HTTPS']) { 
 

 
\t \t \t \t \t $server = HTTPS_CATALOG; 
 

 
\t } else { 
 

 
\t \t \t \t \t $server = HTTP_CATALOG; 
 

 
\t } 
 

 

 

 
\t $data['images'][] = array(
 

 
\t \t \t \t \t 'thumb' => $this->model_tool_image->resize(utf8_substr($image, utf8_strlen(DIR_IMAGE)), 100, 100), 
 

 
\t \t \t \t \t 'name' => implode(' ', $name), 
 

 
\t \t \t \t \t 'type' => 'image', 
 

 
\t \t \t \t \t 'path' => utf8_substr($image, utf8_strlen(DIR_IMAGE)), 
 

 
\t \t \t \t \t 'href' => $server . 'image/' . utf8_substr($image, utf8_strlen(DIR_IMAGE)) 
 

 
\t); 
 

 
} 
 

 
} 
 

 

 

 
$data['heading_title'] = $this->language->get('heading_title'); 
 

 

 

 
$data['text_no_results'] = $this->language->get('text_no_results'); 
 

 
$data['text_confirm'] = $this->language->get('text_confirm'); 
 

 

 

 
$data['entry_search'] = $this->language->get('entry_search'); 
 

 
$data['entry_folder'] = $this->language->get('entry_folder'); 
 

 

 

 
$data['button_parent'] = $this->language->get('button_parent'); 
 

 
$data['button_refresh'] = $this->language->get('button_refresh'); 
 

 
$data['button_upload'] = $this->language->get('button_upload'); 
 

 
$data['button_folder'] = $this->language->get('button_folder'); 
 

 
$data['button_delete'] = $this->language->get('button_delete'); 
 

 
$data['button_search'] = $this->language->get('button_search'); 
 

 

 

 
$data['token'] = $this->session->data['token']; 
 

 

 

 
if (isset($this->request->get['directory'])) { 
 

 
$data['directory'] = urlencode($this->request->get['directory']); 
 

 
} else { 
 

 
$data['directory'] = ''; 
 

 
} 
 

 

 

 
if (isset($this->request->get['filter_name'])) { 
 

 
$data['filter_name'] = $this->request->get['filter_name']; 
 

 
} else { 
 

 
$data['filter_name'] = ''; 
 

 
} 
 

 

 

 
// Return the target ID for the file manager to set the value 
 

 
if (isset($this->request->get['target'])) { 
 

 
$data['target'] = $this->request->get['target']; 
 

 
} else { 
 

 
$data['target'] = ''; 
 

 
} 
 

 

 

 
// Return the thumbnail for the file manager to show a thumbnail 
 

 
if (isset($this->request->get['thumb'])) { 
 

 
$data['thumb'] = $this->request->get['thumb']; 
 

 
} else { 
 

 
$data['thumb'] = ''; 
 

 
} 
 

 

 

 
// Parent 
 

 
$url = ''; 
 

 

 

 
if (isset($this->request->get['directory'])) { 
 

 
$pos = strrpos($this->request->get['directory'], '/'); 
 

 

 

 
if ($pos) { 
 

 
\t $url .= '&directory=' . urlencode(substr($this->request->get['directory'], 0, $pos)); 
 

 
} 
 

 
} 
 

 

 

 
if (isset($this->request->get['target'])) { 
 

 
$url .= '&target=' . $this->request->get['target']; 
 

 
} 
 

 

 

 
if (isset($this->request->get['thumb'])) { 
 

 
$url .= '&thumb=' . $this->request->get['thumb']; 
 

 
} 
 

 

 

 
$data['parent'] = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url, true); 
 

 

 

 
// Refresh 
 

 
$url = ''; 
 

 

 

 
if (isset($this->request->get['directory'])) { 
 

 
$url .= '&directory=' . urlencode($this->request->get['directory']); 
 

 
} 
 

 

 

 
if (isset($this->request->get['target'])) { 
 

 
$url .= '&target=' . $this->request->get['target']; 
 

 
} 
 

 

 

 
if (isset($this->request->get['thumb'])) { 
 

 
$url .= '&thumb=' . $this->request->get['thumb']; 
 

 
} 
 

 

 

 
$data['refresh'] = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url, true); 
 

 

 

 
$url = ''; 
 

 

 

 
if (isset($this->request->get['directory'])) { 
 

 
$url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8')); 
 

 
} 
 

 

 

 
if (isset($this->request->get['filter_name'])) { 
 

 
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 
 

 
} 
 

 

 

 
if (isset($this->request->get['target'])) { 
 

 
$url .= '&target=' . $this->request->get['target']; 
 

 
} 
 

 

 

 
if (isset($this->request->get['thumb'])) { 
 

 
$url .= '&thumb=' . $this->request->get['thumb']; 
 

 
} 
 

 

 

 
$pagination = new Pagination(); 
 

 
$pagination->total = $image_total; 
 

 
$pagination->page = $page; 
 

 
$pagination->limit = 16; 
 

 
$pagination->url = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); 
 

 

 

 
$data['pagination'] = $pagination->render(); 
 

 

 

 
$this->response->setOutput($this->load->view('common/filemanager', $data)); 
 

 
} 
 

 

 

 
public function upload() { 
 

 
$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/' . str_replace(array('../', '..\\', '..'), '', $this->request->get['directory']), '/'); 
 

 
} else { 
 

 
$directory = DIR_IMAGE . 'catalog'; 
 

 
} 
 

 

 

 
// Check its a directory 
 

 
if (!is_dir($directory)) { 
 

 
$json['error'] = $this->language->get('error_directory'); 
 

 
} 
 

 

 

 
if (!$json) { 
 

 
if (!empty($this->request->files['file']['name']) && is_file($this->request->files['file']['tmp_name'])) { 
 

 
\t // Sanitize the filename 
 

 
\t $filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')); 
 

 

 

 
\t // Validate the filename length 
 

 
\t if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 255)) { 
 

 
\t \t \t \t \t $json['error'] = $this->language->get('error_filename'); 
 

 
\t } 
 

 

 

 
\t // Allowed file extension types 
 

 
\t $allowed = array(
 

 
\t \t \t \t \t 'jpg', 
 

 
\t \t \t \t \t 'jpeg', 
 

 
\t \t \t \t \t 'gif', 
 

 
\t \t \t \t \t 'png' 
 

 
\t); 
 

 

 

 
\t if (!in_array(utf8_strtolower(utf8_substr(strrchr($filename, '.'), 1)), $allowed)) { 
 

 
\t \t \t \t \t $json['error'] = $this->language->get('error_filetype'); 
 

 
\t } 
 

 

 

 
\t // Allowed file mime types 
 

 
\t $allowed = array(
 

 
\t \t \t \t \t 'image/jpeg', 
 

 
\t \t \t \t \t 'image/pjpeg', 
 

 
\t \t \t \t \t 'image/png', 
 

 
\t \t \t \t \t 'image/x-png', 
 

 
\t \t \t \t \t 'image/gif' 
 

 
\t); 
 

 

 

 
\t if (!in_array($this->request->files['file']['type'], $allowed)) { 
 

 
\t \t \t \t \t $json['error'] = $this->language->get('error_filetype'); 
 

 
\t } 
 

 

 

 
\t // Return any upload error 
 

 
\t if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) { 
 

 
\t \t \t \t \t $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']); 
 

 
\t } 
 

 
} else { 
 

 
\t $json['error'] = $this->language->get('error_upload'); 
 

 
} 
 

 
} 
 

 

 

 
if (!$json) { 
 

 
move_uploaded_file($this->request->files['file']['tmp_name'], $directory . '/' . $filename); 
 

 

 

 
$json['success'] = $this->language->get('text_uploaded'); 
 

 
} 
 

 

 

 
$this->response->addHeader('Content-Type: application/json'); 
 

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

 
} 
 

 

 

 
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/' . str_replace(array('../', '..\\', '..'), '', $this->request->get['directory']), '/'); 
 

 
} else { 
 

 
$directory = DIR_IMAGE . 'catalog'; 
 

 
} 
 

 

 

 
// Check its a directory 
 

 
if (!is_dir($directory)) { 
 

 
$json['error'] = $this->language->get('error_directory'); 
 

 
} 
 

 

 

 
if (!$json) { 
 

 
// Sanitize the folder name 
 

 
$folder = str_replace(array('../', '..\\', '..'), '', 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)) { 
 

 
\t $json['error'] = $this->language->get('error_folder'); 
 

 
} 
 

 

 

 
// Check if directory already exists or not 
 

 
if (is_dir($directory . '/' . $folder)) { 
 

 
\t $json['error'] = $this->language->get('error_exists'); 
 

 
} 
 

 
} 
 

 

 

 
if (!$json) { 
 

 
mkdir($directory . '/' . $folder, 0777); 
 

 
chmod($directory . '/' . $folder, 0777); 
 

 

 

 
$json['success'] = $this->language->get('text_directory'); 
 

 
} 
 

 

 

 
$this->response->addHeader('Content-Type: application/json'); 
 

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

 
} 
 

 

 

 
public function delete() { 
 

 
$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'); 
 

 
} 
 

 

 

 
if (isset($this->request->post['path'])) { 
 

 
$paths = $this->request->post['path']; 
 

 
} else { 
 

 
$paths = array(); 
 

 
} 
 

 

 

 
// Loop through each path to run validations 
 

 
foreach ($paths as $path) { 
 

 
$path = rtrim(DIR_IMAGE . str_replace(array('../', '..\\', '..'), '', $path), '/'); 
 

 

 

 
// Check path exsists 
 

 
if ($path == DIR_IMAGE . 'catalog') { 
 

 
\t $json['error'] = $this->language->get('error_delete'); 
 

 

 

 
\t break; 
 

 
} 
 

 
} 
 

 

 

 
if (!$json) { 
 

 
// Loop through each path 
 

 
foreach ($paths as $path) { 
 

 
\t $path = rtrim(DIR_IMAGE . str_replace(array('../', '..\\', '..'), '', $path), '/'); 
 

 

 

 
\t // If path is just a file delete it 
 

 
\t if (is_file($path)) { 
 

 
\t \t \t \t \t unlink($path); 
 

 

 

 
\t // If path is a directory beging deleting each file and sub folder 
 

 
\t } elseif (is_dir($path)) { 
 

 
\t \t \t \t \t $files = array(); 
 

 

 

 
\t \t \t \t \t // Make path into an array 
 

 
\t \t \t \t \t $path = array($path . '*'); 
 

 

 

 
\t \t \t \t \t // While the path array is still populated keep looping through 
 

 
\t \t \t \t \t while (count($path) != 0) { 
 

 
\t \t \t \t \t \t \t \t \t $next = array_shift($path); 
 

 

 

 
\t \t \t \t \t \t \t \t \t foreach (glob($next) as $file) { 
 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t // If directory add to path array 
 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t if (is_dir($file)) { 
 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t $path[] = $file . '/*'; 
 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t } 
 

 

 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t // Add the file to the files to be deleted array 
 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t $files[] = $file; 
 

 
\t \t \t \t \t \t \t \t \t } 
 

 
\t \t \t \t \t } 
 

 
\t \t \t \t \t // Reverse sort the file array 
 
    \t \t \t \t \t rsort($files); 
 

 
    \t \t \t \t \t foreach ($files as $file) { 
 

 
\t \t \t \t \t \t \t \t \t // If file just delete 
 

 
\t \t \t \t \t \t \t \t \t if (is_file($file)) { 
 

 
\t \t \t \t \t \t \t \t \t \t \t \t \t unlink($file); 
 

 

 

 
\t \t \t \t \t \t \t \t \t // If directory use the remove directory function 
 

 
\t \t \t \t \t \t \t \t \t } elseif (is_dir($file)) { 
 

 
    \t \t \t \t \t \t rmdir($file); 
 

 
\t \t \t \t \t \t \t \t \t } 
 

 
\t \t \t \t \t } 
 
\t } 
 

 
} 
 
$json['success'] = $this->language->get('text_delete'); 
 

 
} 
 
$this->response->addHeader('Content-Type: application/json'); 
 

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

Antwort

0

Die Antwort hat mir geholfen, teilweise. Ich konnte alle Dateien sehen, aber nicht mehr hochladen. Ich habe einen Fehler bezüglich eines unbekannten Pfades erhalten.

Das funktionierte für mich aber. (Gleiche Datei, die Sie haben geschrieben)

<?php 
 
class ControllerCommonFileManager extends Controller { 
 
\t public function index() { 
 
\t \t $this->load->language('common/filemanager'); 
 

 
\t \t // Find which protocol to use to pass the full image link back 
 
\t \t if ($this->request->server['HTTPS']) { 
 
\t \t \t $server = HTTPS_CATALOG; 
 
\t \t } else { 
 
\t \t \t $server = HTTP_CATALOG; 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['filter_name'])) { 
 
\t \t \t $filter_name = rtrim(str_replace('*', '', $this->request->get['filter_name']), '/'); 
 
\t \t } else { 
 
\t \t \t $filter_name = null; 
 
\t \t } 
 

 
\t \t // Make sure we have the correct directory 
 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $directory = rtrim(DIR_IMAGE . 'catalog/' . str_replace('*', '', $this->request->get['directory']), '/'); 
 
\t \t } else { 
 
\t \t \t $directory = DIR_IMAGE . 'catalog'; 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['page'])) { 
 
\t \t \t $page = $this->request->get['page']; 
 
\t \t } else { 
 
\t \t \t $page = 1; 
 
\t \t } 
 

 
\t \t $directories = array(); 
 
\t \t $files = array(); 
 

 
\t \t $data['images'] = array(); 
 

 
\t \t $this->load->model('tool/image'); 
 

 
\t \t if (substr(str_replace('\\', '/', realpath($directory . '/' . $filter_name)), 0, strlen(DIR_IMAGE . 'catalog')) == DIR_IMAGE . 'catalog') { 
 
\t \t \t // Get directories 
 
\t \t \t $directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR); 
 

 
\t \t \t if (!$directories) { 
 
\t \t \t \t $directories = array(); 
 
\t \t \t } 
 

 
\t \t \t // Get files 
 
\t \t \t $files1 = glob($directory . '/' . $filter_name . '*.jpg'); 
 

 
if (!$files1) { 
 

 
$files1 = array(); 
 

 
} 
 

 

 

 
$files2 = glob($directory . '/' . $filter_name . '*.jpeg'); 
 

 
if (!$files2) { 
 

 
$files2 = array(); 
 

 
} 
 

 

 

 
$files3 = glob($directory . '/' . $filter_name . '*.JPG'); 
 

 
if (!$files3) { 
 

 
$files3 = array(); 
 

 
} 
 

 

 

 
$files4 = glob($directory . '/' . $filter_name . '*.png'); 
 

 
if (!$files4) { 
 

 
$files4 = array(); 
 

 
} 
 

 

 

 
$files5 = glob($directory . '/' . $filter_name . '*.JPEG'); 
 

 
if (!$files5) { 
 

 
$files5 = array(); 
 

 
} 
 

 

 

 
$files6 = glob($directory . '/' . $filter_name . '*.PNG'); 
 

 
if (!$files6) { 
 

 
$files6 = array(); 
 

 
} 
 

 

 

 
$files7 = glob($directory . '/' . $filter_name . '*.GIF'); 
 

 
if (!$files7) { 
 

 
$files7 = array(); 
 

 
} 
 

 
$files8 = glob($directory . '/' . $filter_name . '*.gif'); 
 

 
if (!$files8) { 
 

 
$files8 = array(); 
 

 
} 
 

 

 

 

 

 
$files = array_merge($files1, $files2,$files3,$files4,$files5,$files6,$files7,$files8); 
 

 

 

 
\t \t } 
 

 
\t \t // Merge directories and files 
 
\t \t $images = array_merge($directories, $files); 
 

 
\t \t // Get total number of files and directories 
 
\t \t $image_total = count($images); 
 

 
\t \t // Split the array based on current page number and max number of items per page of 10 
 
\t \t $images = array_splice($images, ($page - 1) * 16, 16); 
 

 
\t \t foreach ($images as $image) { 
 
\t \t \t $name = str_split(basename($image), 14); 
 

 
\t \t \t if (is_dir($image)) { 
 
\t \t \t \t $url = ''; 
 

 
\t \t \t \t if (isset($this->request->get['target'])) { 
 
\t \t \t \t \t $url .= '&target=' . $this->request->get['target']; 
 
\t \t \t \t } 
 

 
\t \t \t \t if (isset($this->request->get['thumb'])) { 
 
\t \t \t \t \t $url .= '&thumb=' . $this->request->get['thumb']; 
 
\t \t \t \t } 
 

 
\t \t \t \t $data['images'][] = array(
 
\t \t \t \t \t 'thumb' => '', 
 
\t \t \t \t \t 'name' => implode(' ', $name), 
 
\t \t \t \t \t 'type' => 'directory', 
 
\t \t \t \t \t 'path' => utf8_substr($image, utf8_strlen(DIR_IMAGE)), 
 
\t \t \t \t \t 'href' => $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . '&directory=' . urlencode(utf8_substr($image, utf8_strlen(DIR_IMAGE . 'catalog/'))) . $url, true) 
 
\t \t \t \t); 
 
\t \t \t } elseif (is_file($image)) { 
 
\t \t \t \t $data['images'][] = array(
 
\t \t \t \t \t 'thumb' => $this->model_tool_image->resize(utf8_substr($image, utf8_strlen(DIR_IMAGE)), 100, 100), 
 
\t \t \t \t \t 'name' => implode(' ', $name), 
 
\t \t \t \t \t 'type' => 'image', 
 
\t \t \t \t \t 'path' => utf8_substr($image, utf8_strlen(DIR_IMAGE)), 
 
\t \t \t \t \t 'href' => $server . 'image/' . utf8_substr($image, utf8_strlen(DIR_IMAGE)) 
 
\t \t \t \t); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $data['heading_title'] = $this->language->get('heading_title'); 
 

 
\t \t $data['text_no_results'] = $this->language->get('text_no_results'); 
 
\t \t $data['text_confirm'] = $this->language->get('text_confirm'); 
 

 
\t \t $data['entry_search'] = $this->language->get('entry_search'); 
 
\t \t $data['entry_folder'] = $this->language->get('entry_folder'); 
 

 
\t \t $data['button_parent'] = $this->language->get('button_parent'); 
 
\t \t $data['button_refresh'] = $this->language->get('button_refresh'); 
 
\t \t $data['button_upload'] = $this->language->get('button_upload'); 
 
\t \t $data['button_folder'] = $this->language->get('button_folder'); 
 
\t \t $data['button_delete'] = $this->language->get('button_delete'); 
 
\t \t $data['button_search'] = $this->language->get('button_search'); 
 

 
\t \t $data['token'] = $this->session->data['token']; 
 

 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $data['directory'] = urlencode($this->request->get['directory']); 
 
\t \t } else { 
 
\t \t \t $data['directory'] = ''; 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['filter_name'])) { 
 
\t \t \t $data['filter_name'] = $this->request->get['filter_name']; 
 
\t \t } else { 
 
\t \t \t $data['filter_name'] = ''; 
 
\t \t } 
 

 
\t \t // Return the target ID for the file manager to set the value 
 
\t \t if (isset($this->request->get['target'])) { 
 
\t \t \t $data['target'] = $this->request->get['target']; 
 
\t \t } else { 
 
\t \t \t $data['target'] = ''; 
 
\t \t } 
 

 
\t \t // Return the thumbnail for the file manager to show a thumbnail 
 
\t \t if (isset($this->request->get['thumb'])) { 
 
\t \t \t $data['thumb'] = $this->request->get['thumb']; 
 
\t \t } else { 
 
\t \t \t $data['thumb'] = ''; 
 
\t \t } 
 

 
\t \t // Parent 
 
\t \t $url = ''; 
 

 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $pos = strrpos($this->request->get['directory'], '/'); 
 

 
\t \t \t if ($pos) { 
 
\t \t \t \t $url .= '&directory=' . urlencode(substr($this->request->get['directory'], 0, $pos)); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['target'])) { 
 
\t \t \t $url .= '&target=' . $this->request->get['target']; 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['thumb'])) { 
 
\t \t \t $url .= '&thumb=' . $this->request->get['thumb']; 
 
\t \t } 
 

 
\t \t $data['parent'] = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url, true); 
 

 
\t \t // Refresh 
 
\t \t $url = ''; 
 

 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $url .= '&directory=' . urlencode($this->request->get['directory']); 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['target'])) { 
 
\t \t \t $url .= '&target=' . $this->request->get['target']; 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['thumb'])) { 
 
\t \t \t $url .= '&thumb=' . $this->request->get['thumb']; 
 
\t \t } 
 

 
\t \t $data['refresh'] = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url, true); 
 

 
\t \t $url = ''; 
 

 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8')); 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['filter_name'])) { 
 
\t \t \t $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['target'])) { 
 
\t \t \t $url .= '&target=' . $this->request->get['target']; 
 
\t \t } 
 

 
\t \t if (isset($this->request->get['thumb'])) { 
 
\t \t \t $url .= '&thumb=' . $this->request->get['thumb']; 
 
\t \t } 
 

 
\t \t $pagination = new Pagination(); 
 
\t \t $pagination->total = $image_total; 
 
\t \t $pagination->page = $page; 
 
\t \t $pagination->limit = 16; 
 
\t \t $pagination->url = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); 
 

 
\t \t $data['pagination'] = $pagination->render(); 
 

 
\t \t $this->response->setOutput($this->load->view('common/filemanager', $data)); 
 
\t } 
 

 
\t public function upload() { 
 
\t \t $this->load->language('common/filemanager'); 
 

 
\t \t $json = array(); 
 

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

 
\t \t // Make sure we have the correct directory 
 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $directory = rtrim(DIR_IMAGE . 'catalog/' . $this->request->get['directory'], '/'); 
 
\t \t } else { 
 
\t \t \t $directory = DIR_IMAGE . 'catalog'; 
 
\t \t } 
 

 
\t \t // Check its a directory 
 
\t \t if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)), 0, strlen(DIR_IMAGE . 'catalog')) != DIR_IMAGE . 'catalog') { 
 
\t \t \t $json['error'] = $this->language->get('error_directory'); 
 
\t \t } 
 

 
\t \t if (!$json) { 
 
\t \t \t // Check if multiple files are uploaded or just one 
 
\t \t \t $files = array(); 
 

 
\t \t \t if (!empty($this->request->files['file']['name']) && is_array($this->request->files['file']['name'])) { 
 
\t \t \t \t foreach (array_keys($this->request->files['file']['name']) as $key) { 
 
\t \t \t \t \t $files[] = array(
 
\t \t \t \t \t \t 'name'  => $this->request->files['file']['name'][$key], 
 
\t \t \t \t \t \t 'type'  => $this->request->files['file']['type'][$key], 
 
\t \t \t \t \t \t 'tmp_name' => $this->request->files['file']['tmp_name'][$key], 
 
\t \t \t \t \t \t 'error' => $this->request->files['file']['error'][$key], 
 
\t \t \t \t \t \t 'size'  => $this->request->files['file']['size'][$key] 
 
\t \t \t \t \t); 
 
\t \t \t \t } 
 
\t \t \t } 
 

 
\t \t \t foreach ($files as $file) { 
 
\t \t \t \t if (is_file($file['tmp_name'])) { 
 
\t \t \t \t \t // Sanitize the filename 
 
\t \t \t \t \t $filename = basename(html_entity_decode($file['name'], ENT_QUOTES, 'UTF-8')); 
 

 
\t \t \t \t \t // Validate the filename length 
 
\t \t \t \t \t if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 255)) { 
 
\t \t \t \t \t \t $json['error'] = $this->language->get('error_filename'); 
 
\t \t \t \t \t } 
 
\t \t \t \t \t 
 
\t \t \t \t \t // Allowed file extension types 
 
\t \t \t \t \t $allowed = array(
 
\t \t \t \t \t \t 'jpg', 
 
\t \t \t \t \t \t 'jpeg', 
 
\t \t \t \t \t \t 'gif', 
 
\t \t \t \t \t \t 'png' 
 
\t \t \t \t \t); 
 
\t 
 
\t \t \t \t \t if (!in_array(utf8_strtolower(utf8_substr(strrchr($filename, '.'), 1)), $allowed)) { 
 
\t \t \t \t \t \t $json['error'] = $this->language->get('error_filetype'); 
 
\t \t \t \t \t } 
 
\t \t \t \t \t 
 
\t \t \t \t \t // Allowed file mime types 
 
\t \t \t \t \t $allowed = array(
 
\t \t \t \t \t \t 'image/jpeg', 
 
\t \t \t \t \t \t 'image/pjpeg', 
 
\t \t \t \t \t \t 'image/png', 
 
\t \t \t \t \t \t 'image/x-png', 
 
\t \t \t \t \t \t 'image/gif' 
 
\t \t \t \t \t); 
 
\t 
 
\t \t \t \t \t if (!in_array($file['type'], $allowed)) { 
 
\t \t \t \t \t \t $json['error'] = $this->language->get('error_filetype'); 
 
\t \t \t \t \t } 
 

 
\t \t \t \t \t // Return any upload error 
 
\t \t \t \t \t if ($file['error'] != UPLOAD_ERR_OK) { 
 
\t \t \t \t \t \t $json['error'] = $this->language->get('error_upload_' . $file['error']); 
 
\t \t \t \t \t } 
 
\t \t \t \t } else { 
 
\t \t \t \t \t $json['error'] = $this->language->get('error_upload'); 
 
\t \t \t \t } 
 

 
\t \t \t \t if (!$json) { 
 
\t \t \t \t \t move_uploaded_file($file['tmp_name'], $directory . '/' . $filename); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (!$json) { 
 
\t \t \t $json['success'] = $this->language->get('text_uploaded'); 
 
\t \t } 
 

 
\t \t $this->response->addHeader('Content-Type: application/json'); 
 
\t \t $this->response->setOutput(json_encode($json)); 
 
\t } 
 

 
\t public function folder() { 
 
\t \t $this->load->language('common/filemanager'); 
 

 
\t \t $json = array(); 
 

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

 
\t \t // Make sure we have the correct directory 
 
\t \t if (isset($this->request->get['directory'])) { 
 
\t \t \t $directory = rtrim(DIR_IMAGE . 'catalog/' . $this->request->get['directory'], '/'); 
 
\t \t } else { 
 
\t \t \t $directory = DIR_IMAGE . 'catalog'; 
 
\t \t } 
 

 
\t \t // Check its a directory 
 
\t \t if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)), 0, strlen(DIR_IMAGE . 'catalog')) != DIR_IMAGE . 'catalog') { 
 
\t \t \t $json['error'] = $this->language->get('error_directory'); 
 
\t \t } 
 

 
\t \t if ($this->request->server['REQUEST_METHOD'] == 'POST') { 
 
\t \t \t // Sanitize the folder name 
 
\t \t \t $folder = basename(html_entity_decode($this->request->post['folder'], ENT_QUOTES, 'UTF-8')); 
 

 
\t \t \t // Validate the filename length 
 
\t \t \t if ((utf8_strlen($folder) < 3) || (utf8_strlen($folder) > 128)) { 
 
\t \t \t \t $json['error'] = $this->language->get('error_folder'); 
 
\t \t \t } 
 

 
\t \t \t // Check if directory already exists or not 
 
\t \t \t if (is_dir($directory . '/' . $folder)) { 
 
\t \t \t \t $json['error'] = $this->language->get('error_exists'); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (!isset($json['error'])) { 
 
\t \t \t mkdir($directory . '/' . $folder, 0777); 
 
\t \t \t chmod($directory . '/' . $folder, 0777); 
 

 
\t \t \t @touch($directory . '/' . $folder . '/' . 'index.html'); 
 

 
\t \t \t $json['success'] = $this->language->get('text_directory'); 
 
\t \t } 
 

 
\t \t $this->response->addHeader('Content-Type: application/json'); 
 
\t \t $this->response->setOutput(json_encode($json)); 
 
\t } 
 

 
\t public function delete() { 
 
\t \t $this->load->language('common/filemanager'); 
 

 
\t \t $json = array(); 
 

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

 
\t \t if (isset($this->request->post['path'])) { 
 
\t \t \t $paths = $this->request->post['path']; 
 
\t \t } else { 
 
\t \t \t $paths = array(); 
 
\t \t } 
 

 
\t \t // Loop through each path to run validations 
 
\t \t foreach ($paths as $path) { 
 
\t \t \t // Check path exsists 
 
\t \t \t if ($path == DIR_IMAGE . 'catalog' || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $path)), 0, strlen(DIR_IMAGE . 'catalog')) != DIR_IMAGE . 'catalog') { 
 
\t \t \t \t $json['error'] = $this->language->get('error_delete'); 
 

 
\t \t \t \t break; 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (!$json) { 
 
\t \t \t // Loop through each path 
 
\t \t \t foreach ($paths as $path) { 
 
\t \t \t \t $path = rtrim(DIR_IMAGE . $path, '/'); 
 

 
\t \t \t \t // If path is just a file delete it 
 
\t \t \t \t if (is_file($path)) { 
 
\t \t \t \t \t unlink($path); 
 

 
\t \t \t \t // If path is a directory beging deleting each file and sub folder 
 
\t \t \t \t } elseif (is_dir($path)) { 
 
\t \t \t \t \t $files = array(); 
 

 
\t \t \t \t \t // Make path into an array 
 
\t \t \t \t \t $path = array($path . '*'); 
 

 
\t \t \t \t \t // While the path array is still populated keep looping through 
 
\t \t \t \t \t while (count($path) != 0) { 
 
\t \t \t \t \t \t $next = array_shift($path); 
 

 
\t \t \t \t \t \t foreach (glob($next) as $file) { 
 
\t \t \t \t \t \t \t // If directory add to path array 
 
\t \t \t \t \t \t \t if (is_dir($file)) { 
 
\t \t \t \t \t \t \t \t $path[] = $file . '/*'; 
 
\t \t \t \t \t \t \t } 
 

 
\t \t \t \t \t \t \t // Add the file to the files to be deleted array 
 
\t \t \t \t \t \t \t $files[] = $file; 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 

 
\t \t \t \t \t // Reverse sort the file array 
 
\t \t \t \t \t rsort($files); 
 

 
\t \t \t \t \t foreach ($files as $file) { 
 
\t \t \t \t \t \t // If file just delete 
 
\t \t \t \t \t \t if (is_file($file)) { 
 
\t \t \t \t \t \t \t unlink($file); 
 

 
\t \t \t \t \t \t // If directory use the remove directory function 
 
\t \t \t \t \t \t } elseif (is_dir($file)) { 
 
\t \t \t \t \t \t \t rmdir($file); 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t } 
 

 
\t \t \t $json['success'] = $this->language->get('text_delete'); 
 
\t \t } 
 

 
\t \t $this->response->addHeader('Content-Type: application/json'); 
 
\t \t $this->response->setOutput(json_encode($json)); 
 
\t } 
 
}

Verwandte Themen