Пример #1
0
	function getNameFromFile($file)
	{
		$tab = explode("/" , $file);
									
		$name =  str_replace("%20" , " " , $tab[count($tab) - 1]);
											
		$name =  str_replace("?m=" , " " , $name);
		
		$name= str_replace("?dl=0" , "" , $name);
		
		$name =  urldecode($name);
		
		if(!empty($name))
			$name = truncateFilename($name);
		
		return $name;
	}
Пример #2
0
 public function upload()
 {
     $ssl = isset($_SERVER['HTTPS']) ? 'SSL' : 'NONSSL';
     $this->load->language('myoc/copu');
     $this->load->model('myoc/copu');
     $this->load->model('tool/upload');
     $type = $this->request->get['type'];
     $type_id = isset($this->request->get['type_id']) ? $this->request->get['type_id'] : false;
     $product_option_id = isset($this->request->get['product_option_id']) ? $this->request->get['product_option_id'] : false;
     $copu_product_id = isset($this->request->get['copu_product_id']) ? $this->request->get['copu_product_id'] : false;
     $session = isset($this->request->get['session']) ? $this->request->get['session'] : true;
     $copu_products = $this->config->get('copu_products');
     $copu_product = false;
     if ($copu_products) {
         foreach ($copu_products as $copu_product_value) {
             if ($copu_product_id && $copu_product_value['copu_product_id'] == $copu_product_id) {
                 $copu_product = $copu_product_value;
                 break;
             }
         }
     }
     if ($copu_product) {
         $copu_status = $copu_product['status'];
         $copu_stores = isset($copu_product['stores']) ? $copu_product['stores'] : array();
         $copu_login = $copu_product['login'];
         $copu_customer_groups = isset($copu_product['customer_groups']) ? $copu_product['customer_groups'] : array();
         $copu_limit = $copu_product['limit'];
         $copu_filetypes = isset($copu_product['filetypes']) ? $copu_product['filetypes'] : array();
         $copu_max_filesize = $copu_product['max_filesize'];
         $copu_max_dimension_w = $copu_product['max_dimension_w'];
         $copu_max_dimension_h = $copu_product['max_dimension_h'];
         $copu_image_channel = $copu_product['image_channel'];
         $copu_max_filename_length = $copu_product['max_filename_length'];
         $copu_file_location = empty($copu_product['file_location']) ? "" : "../" . $copu_product['file_location'] . "/";
         $copu_preview = $copu_product['preview'];
         $copu_replace = $copu_product['replace'];
         $copu_preview_dimension_w = $copu_product['preview_dimension_w'];
         $copu_preview_dimension_h = $copu_product['preview_dimension_h'];
     } else {
         $copu_status = $this->config->get('copu_' . $type . '_status');
         $copu_stores = $this->config->get('copu_' . $type . '_stores');
         $copu_login = $this->config->get('copu_' . $type . '_login');
         $copu_customer_groups = $this->config->get('copu_' . $type . '_customer_groups');
         $copu_limit = $this->config->get('copu_' . $type . '_limit');
         $copu_filetypes = $this->config->get('copu_' . $type . '_filetypes');
         $copu_max_filesize = $this->config->get('copu_' . $type . '_max_filesize');
         $copu_max_dimension_w = $this->config->get('copu_' . $type . '_max_dimension_w');
         $copu_max_dimension_h = $this->config->get('copu_' . $type . '_max_dimension_h');
         $copu_image_channel = $this->config->get('copu_' . $type . '_image_channel');
         $copu_max_filename_length = $this->config->get('copu_' . $type . '_max_filename_length');
         $copu_file_location = $this->config->get('copu_' . $type . '_file_location') ? "../" . $this->config->get('copu_' . $type . '_file_location') . "/" : "";
         $copu_preview = $this->config->get('copu_' . $type . '_preview');
         $copu_preview_dimension_w = $this->config->get('copu_' . $type . '_preview_dimension_w');
         $copu_preview_dimension_h = $this->config->get('copu_' . $type . '_preview_dimension_h');
         $copu_replace = false;
     }
     if (!empty($copu_file_location)) {
         if (strpos($copu_file_location, '%customer_id%')) {
             if ($this->customer->isLogged()) {
                 $copu_file_location = str_replace('%customer_id%', $this->customer->isLogged(), $copu_file_location);
             } else {
                 $copu_file_location = "";
             }
         }
         if (strpos($copu_file_location, '%product_id%') && $type == 'product' && $type_id) {
             $copu_file_location = str_replace('%product_id%', $type_id, $copu_file_location);
         }
         if (strpos($copu_file_location, '%order_id%')) {
             if ($type == 'order' && $type_id && !$session) {
                 $copu_file_location = str_replace('%order_id%', $type_id, $copu_file_location);
             } else {
                 $copu_file_location = "";
             }
         }
     }
     if (!empty($copu_file_location) && !file_exists(DIR_UPLOAD . $copu_file_location)) {
         mkdir(DIR_UPLOAD . $copu_file_location, 0755, true);
     }
     $json = array();
     //create upload session
     if (!isset($this->session->data['copu_' . $type . '_uploads']) && $session) {
         $this->session->data['copu_' . $type . '_uploads'] = array();
     }
     if ($type == 'product' && $type_id && !isset($this->session->data['copu_' . $type . '_uploads'][$type_id])) {
         $this->session->data['copu_' . $type . '_uploads'][$type_id] = array();
     }
     if ($type == 'product' && $type_id && $product_option_id && !isset($this->session->data['copu_' . $type . '_uploads'][$type_id][$product_option_id])) {
         $this->session->data['copu_' . $type . '_uploads'][$type_id][$product_option_id] = array();
     }
     //check status and store
     if (!$copu_status || $copu_stores == "" || !in_array($this->config->get('config_store_id'), $copu_stores)) {
         $json['error'] = $this->language->get('error_upload_status');
         $this->response->setOutput(json_encode($json));
         return;
     }
     //check login
     if ($copu_login && ($session xor $type == 'customer') && (!$this->customer->isLogged() || !$copu_customer_groups || !in_array($this->customer->getGroupId(), $copu_customer_groups))) {
         $json['error'] = $this->language->get('error_login');
         $this->response->setOutput(json_encode($json));
         return;
     }
     //check file limit
     $upload_total = 0;
     if ($type != 'product' && isset($this->session->data['copu_' . $type . '_uploads'])) {
         $upload_total = count($this->session->data['copu_' . $type . '_uploads']);
     }
     if ($type == 'product' && $this->session->data['copu_' . $type . '_uploads'][$type_id][$product_option_id]) {
         $upload_total = count($this->session->data['copu_' . $type . '_uploads'][$type_id][$product_option_id]);
     }
     if (!$session) {
         if ($type == 'customer') {
             $type_id = $this->customer->isLogged();
         }
         $upload_total = $this->model_myoc_copu->getTotalUploads(array('type' => $type, 'type_id' => $type_id));
     }
     if ($upload_total >= $copu_limit) {
         $json['error'] = $this->language->get('error_limit');
         $this->response->setOutput(json_encode($json));
         return;
     }
     $filetypes = $this->model_myoc_copu->getFiletypes($copu_filetypes);
     if (!empty($this->request->files['file']['name'])) {
         $filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
         if (strlen($filename) < 3 || strlen($filename) > 64) {
             $json['error'] = $this->language->get('error_filename');
         }
         $allowed_ext = array();
         $allowed_mime = array();
         foreach ($filetypes as $filetype) {
             $allowed_ext[] = trim($filetype['ext']);
             $allowed_mime[trim($filetype['ext'])] = $filetype['mime'] == '' ? false : explode(",", $filetype['mime']);
         }
         $ext = strtolower(substr(strrchr($filename, '.'), 1));
         $mime = function_exists('mime_content_type') ? mime_content_type($this->request->files['file']['tmp_name']) : false;
         //check file ext and mime
         if (!in_array($ext, $allowed_ext) || $mime && $allowed_mime[$ext] && !in_array($mime, $allowed_mime[$ext])) {
             $json['error'] = sprintf($this->language->get('error_filetype'), implode(", ", $allowed_ext));
         }
         //check file size
         if (filesize($this->request->files['file']['tmp_name']) > $copu_max_filesize * 1024) {
             $json['error'] = sprintf($this->language->get('error_filesize'), formatFilesize($copu_max_filesize * 1024));
         }
         if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
             $imageinfo = @getimagesize($this->request->files['file']['tmp_name']);
             if ($imageinfo[2] > 0 && $imageinfo[2] < 4) {
                 //check image file dimension
                 if ($copu_max_dimension_w && $copu_max_dimension_h && ($imageinfo[0] > $copu_max_dimension_w || $imageinfo[1] > $copu_max_dimension_h)) {
                     $json['error'] = sprintf($this->language->get('error_dimension'), $copu_max_dimension_w, $copu_max_dimension_h);
                 }
                 //check image channel
                 if ($copu_image_channel && $imageinfo['channels'] != $copu_image_channel) {
                     $channel = '';
                     if ($copu_image_channel == 3) {
                         $channel = $this->language->get('text_rgb');
                     }
                     if ($copu_image_channel == 4) {
                         $channel = $this->language->get('text_cmyk');
                     }
                     $json['error'] = sprintf($this->language->get('error_image_channel'), $channel);
                 }
             }
         }
         //check other system upload error
         if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
             $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
         }
         // Check to see if any PHP files are trying to be uploaded
         $content = file_get_contents($this->request->files['file']['tmp_name']);
         if (preg_match('/\\<\\?php/i', $content)) {
             $json['error'] = sprintf($this->language->get('error_filetype'), implode(", ", $allowed_ext));
         }
     } else {
         $json['error'] = $this->language->get('error_upload');
     }
     if (!$json) {
         if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
             $upload_id = md5(mt_rand());
             $file = $filename . '.' . $upload_id;
             move_uploaded_file($this->request->files['file']['tmp_name'], DIR_UPLOAD . $copu_file_location . $file);
             if (method_exists($this->encryption, 'encrypt')) {
                 $encryption = $this->encryption;
             } else {
                 $this->load->library('encryption');
                 $encryption = new Encryption($this->config->get('config_encryption'));
             }
             if (!$session) {
                 $json['code'] = $this->model_tool_upload->addUpload($filename, $copu_file_location . $file);
                 $upload_info = $this->model_tool_upload->getUploadByCode($json['code']);
                 $upload_id = $this->model_myoc_copu->addUpload(array('filename' => $copu_file_location . $file, $type . '_id' => $type_id, 'upload_id' => $upload_info['upload_id']));
                 if ($type == 'order' && $this->config->get('copu_order_history_modify_status')) {
                     $this->load->model('checkout/order');
                     $order_info = $this->model_checkout_order->getOrder($type_id);
                     if ($order_info['order_status_id'] > 0) {
                         $this->model_checkout_order->addOrderHistory($type_id, $this->config->get('copu_order_history_modify_status'), $this->language->get('text_uploaded') . ' ' . $filename, true);
                     }
                 }
             } elseif ($type == 'product' && $type_id && $product_option_id) {
                 $json['code'] = $this->model_tool_upload->addUpload($filename, $copu_file_location . $file);
                 $this->session->data['copu_' . $type . '_uploads'][$type_id][$product_option_id][$upload_id] = $json['code'];
                 //$encryption->encrypt($copu_file_location . $file);
             } else {
                 $this->session->data['copu_' . $type . '_uploads'][$upload_id] = $encryption->encrypt($copu_file_location . $file);
             }
             $this->load->model('tool/image');
             $image = false;
             $popup = false;
             $replace = false;
             if (($copu_preview || $copu_replace) && $file && filesize(DIR_UPLOAD . $copu_file_location . $file)) {
                 $imageinfo = @getimagesize(DIR_UPLOAD . $copu_file_location . $file);
                 if ($imageinfo[2] > 0 && $imageinfo[2] < 4) {
                     $random_str = md5($upload_id);
                     copy(DIR_UPLOAD . $copu_file_location . $file, DIR_IMAGE . $random_str . $filename);
                     $image = $copu_preview ? $this->model_tool_image->resize($random_str . $filename, $copu_preview_dimension_w, $copu_preview_dimension_h) : false;
                     $popup = $copu_preview || $copu_replace ? $this->model_tool_image->resize($random_str . $filename, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')) : false;
                     $replace = $type == 'product' && $copu_replace ? $this->model_tool_image->resize($random_str . $filename, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height')) : false;
                     unlink(DIR_IMAGE . $random_str . $filename);
                 } else {
                     $image = $copu_preview ? $this->model_tool_image->resize('no_image.png', $copu_preview_dimension_w, $copu_preview_dimension_h) : false;
                 }
             }
             $json['file'] = array();
             $json['file']['upload_id'] = $upload_id;
             $json['file']['image'] = $image;
             $json['file']['popup'] = $popup;
             $json['file']['replace'] = $replace;
             $json['file']['name'] = truncateFilename($filename, $copu_max_filename_length);
             $json['file']['href'] = $this->url->link('myoc/copu/download', 'f=' . urlencode($encryption->encrypt($copu_file_location . $file)), $ssl);
             $json['file']['date'] = date($this->language->get('date_format_short'));
             $json['file']['size'] = formatFilesize($this->request->files['file']['size']);
             $json['file']['delete'] = $this->url->link('myoc/copu/delete', 'upload_id=' . $upload_id, $ssl);
         }
         $json['success'] = true;
     }
     $this->response->setOutput(json_encode($json));
 }
Пример #3
0
		// PDF
		/////////////////////////////////////////////////////////////
		
		$file = rwmb_meta( 'PRODUCT_pdf_file', '' , $post->ID);
		
		if(!empty($file))
		{
				
			echo "<tr><td class = 'title' style = 'padding:10px;'>Product sheet</td></tr>";
			echo "<tr><td style = 'padding:10px;'>";
				
			$file = str_replace("www" , "dl" , $file);
			
			$url = "http://www.qcsasia.com/qcs-admin/action/downloadFile.php?link=" . $file;
			
			$filename = truncateFilename(getNameFromFile($file));
			
			if (!isset($_SESSION['qcs-isconnect']))
			{
				$file = "/member-area-index";
			}
			
			echo "<a href = '" . $file . "'>" . $filename . "</a><br/>\n";
				
			echo "</tr></td>";
				
		}
		

		echo "</table>";
								
Пример #4
0
 public function upload()
 {
     $this->load->language('module/myoccopu');
     $json = array();
     if (!$this->user->hasPermission('modify', 'module/myoccopu')) {
         $json['error'] = $this->language->get('error_permission');
     }
     $type = isset($this->request->get['type']) ? $this->request->get['type'] : "";
     $copu_products = $this->config->get('copu_products');
     $option_id = isset($this->request->get['option_id']) ? $this->request->get['option_id'] : false;
     if ($type == 'product' && $copu_products && $option_id) {
         foreach ($copu_products as $copu_product) {
             if (isset($copu_product['options']) && in_array($option_id, $copu_product['options'])) {
                 $copu_force_qty = $copu_product['force_qty'];
                 $copu_max_filename_length = $copu_product['max_filename_length'];
                 $copu_file_location = $copu_product['file_location'] ? "../" . $copu_product['file_location'] . "/" : "";
                 $copu_preview_dimension_w = $copu_product['preview_dimension_w'];
                 $copu_preview_dimension_h = $copu_product['preview_dimension_h'];
                 break;
             }
         }
     } else {
         $copu_force_qty = $this->config->get('copu_' . $type . '_force_qty');
         $copu_max_filename_length = $this->config->get('copu_' . $type . '_max_filename_length');
         $copu_file_location = $this->config->get('copu_' . $type . '_file_location') ? "../" . $this->config->get('copu_' . $type . '_file_location') . "/" : "";
         $copu_preview_dimension_w = $this->config->get('copu_' . $type . '_preview_dimension_w');
         $copu_preview_dimension_h = $this->config->get('copu_' . $type . '_preview_dimension_h');
     }
     if (!empty($copu_file_location)) {
         if (strpos($copu_file_location, '%customer_id%')) {
             $copu_file_location = str_replace('%customer_id%', $this->request->get['customer_id'], $copu_file_location);
         }
         if (strpos($copu_file_location, '%product_id%') && $type == 'product' && $this->request->get['product_id']) {
             $copu_file_location = str_replace('%product_id%', $this->request->get['product_id'], $copu_file_location);
         }
         if (strpos($copu_file_location, '%order_id%')) {
             $copu_file_location = str_replace('%order_id%', $this->request->get['order_id'], $copu_file_location);
         }
     }
     if (!empty($copu_file_location) && !file_exists(DIR_UPLOAD . $copu_file_location)) {
         mkdir(DIR_UPLOAD . $copu_file_location, 0755, true);
     }
     $this->load->model('myoc/copu');
     if (!empty($this->request->files['file']['name'])) {
         $filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
         if (strlen($filename) < 3 || strlen($filename) > 64) {
             $json['error'] = $this->language->get('error_filename');
         }
         //check other system upload error
         if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
             $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
         }
     } else {
         $json['error'] = $this->language->get('error_upload');
     }
     if (!$json) {
         if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name']) && $this->request->files['file']['size']) {
             $upload_id = md5(mt_rand());
             $file = $filename . '.' . $upload_id;
             move_uploaded_file($this->request->files['file']['tmp_name'], DIR_UPLOAD . $copu_file_location . $file);
             $this->load->model('tool/upload');
             $upload_code = $this->model_tool_upload->addUpload($filename, $copu_file_location . $file);
             $upload_info = $this->model_tool_upload->getUploadByCode($upload_code);
             //$upload_id = $this->model_myoc_copu->addUpload(array('filename' => $copu_file_location . $file));
             $upload_id = $upload_info['upload_id'];
             $this->load->model('tool/image');
             $imageinfo = @getimagesize(DIR_UPLOAD . $copu_file_location . $file);
             if ($imageinfo[2] > 0 && $imageinfo[2] < 4) {
                 $random_str = md5($upload_code);
                 copy(DIR_UPLOAD . $copu_file_location . $file, DIR_IMAGE . $random_str . $filename);
                 $image = $this->model_tool_image->resize($random_str . $filename, $copu_preview_dimension_w, $copu_preview_dimension_h);
                 $popup = $this->model_tool_image->resize($random_str . $filename, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
                 unlink(DIR_IMAGE . $random_str . $filename);
             } else {
                 $image = $this->model_tool_image->resize('no_image.png', $copu_preview_dimension_w, $copu_preview_dimension_h);
                 $popup = false;
             }
             $json['file'] = array();
             $json['file']['upload_id'] = $upload_id;
             $json['file']['file'] = $copu_file_location . $file;
             $json['file']['code'] = $upload_code;
             $json['file']['image'] = $image;
             $json['file']['popup'] = $popup;
             $json['file']['name'] = truncateFilename($filename, $copu_max_filename_length);
             $json['file']['href'] = $this->url->link('myoc/copu/download', 'token=' . $this->session->data['token'] . '&f=' . urlencode($copu_file_location . $file), 'SSL');
             $json['file']['date'] = date($this->language->get('date_format_short'));
             $json['file']['size'] = formatFilesize($this->request->files['file']['size']);
             $json['file']['force_qty'] = $copu_force_qty ? true : false;
             $json['file']['delete'] = $this->url->link('myoc/copu/delete', 'token=' . $this->session->data['token'] . '&upload_id=' . $upload_id, 'SSL');
         }
         $json['success'] = true;
     }
     $this->response->setOutput(json_encode($json));
 }