PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/upload/catalog/controller/product/product.php

https://github.com/opencartlite/opencart
PHP | 687 lines | 518 code | 165 blank | 4 comment | 123 complexity | f6333044d7feee653ae91980aab50ff1 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-3.0
  1. <?php
  2. class ControllerProductProduct extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->data += $this->language->load('product/product');
  6. $this->data['breadcrumbs'] = array();
  7. $this->data['breadcrumbs'][] = array(
  8. 'text' => $this->language->get('text_home'),
  9. 'href' => $this->url->link('common/home')
  10. );
  11. $this->load->model('catalog/category');
  12. if (isset($this->request->get['path'])) {
  13. $path = '';
  14. $parts = explode('_', (string)$this->request->get['path']);
  15. $category_id = (int)array_pop($parts);
  16. foreach ($parts as $path_id) {
  17. if (!$path) {
  18. $path = $path_id;
  19. } else {
  20. $path .= '_' . $path_id;
  21. }
  22. $category_info = $this->model_catalog_category->getCategory($path_id);
  23. if ($category_info) {
  24. $this->data['breadcrumbs'][] = array(
  25. 'text' => $category_info['name'],
  26. 'href' => $this->url->link('product/category', 'path=' . $path)
  27. );
  28. }
  29. }
  30. // Set the last category breadcrumb
  31. $category_info = $this->model_catalog_category->getCategory($category_id);
  32. if ($category_info) {
  33. $url = '';
  34. if (isset($this->request->get['sort'])) {
  35. $url .= '&sort=' . $this->request->get['sort'];
  36. }
  37. if (isset($this->request->get['order'])) {
  38. $url .= '&order=' . $this->request->get['order'];
  39. }
  40. if (isset($this->request->get['page'])) {
  41. $url .= '&page=' . $this->request->get['page'];
  42. }
  43. if (isset($this->request->get['limit'])) {
  44. $url .= '&limit=' . $this->request->get['limit'];
  45. }
  46. $this->data['breadcrumbs'][] = array(
  47. 'text' => $category_info['name'],
  48. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'])
  49. );
  50. }
  51. }
  52. $this->load->model('catalog/manufacturer');
  53. if (isset($this->request->get['manufacturer_id'])) {
  54. $this->data['breadcrumbs'][] = array(
  55. 'text' => $this->language->get('text_brand'),
  56. 'href' => $this->url->link('product/manufacturer')
  57. );
  58. $url = '';
  59. if (isset($this->request->get['sort'])) {
  60. $url .= '&sort=' . $this->request->get['sort'];
  61. }
  62. if (isset($this->request->get['order'])) {
  63. $url .= '&order=' . $this->request->get['order'];
  64. }
  65. if (isset($this->request->get['page'])) {
  66. $url .= '&page=' . $this->request->get['page'];
  67. }
  68. if (isset($this->request->get['limit'])) {
  69. $url .= '&limit=' . $this->request->get['limit'];
  70. }
  71. $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
  72. if ($manufacturer_info) {
  73. $this->data['breadcrumbs'][] = array(
  74. 'text' => $manufacturer_info['name'],
  75. 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
  76. );
  77. }
  78. }
  79. if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
  80. $url = '';
  81. if (isset($this->request->get['search'])) {
  82. $url .= '&search=' . $this->request->get['search'];
  83. }
  84. if (isset($this->request->get['tag'])) {
  85. $url .= '&tag=' . $this->request->get['tag'];
  86. }
  87. if (isset($this->request->get['description'])) {
  88. $url .= '&description=' . $this->request->get['description'];
  89. }
  90. if (isset($this->request->get['category_id'])) {
  91. $url .= '&category_id=' . $this->request->get['category_id'];
  92. }
  93. if (isset($this->request->get['sub_category'])) {
  94. $url .= '&sub_category=' . $this->request->get['sub_category'];
  95. }
  96. if (isset($this->request->get['sort'])) {
  97. $url .= '&sort=' . $this->request->get['sort'];
  98. }
  99. if (isset($this->request->get['order'])) {
  100. $url .= '&order=' . $this->request->get['order'];
  101. }
  102. if (isset($this->request->get['page'])) {
  103. $url .= '&page=' . $this->request->get['page'];
  104. }
  105. if (isset($this->request->get['limit'])) {
  106. $url .= '&limit=' . $this->request->get['limit'];
  107. }
  108. $this->data['breadcrumbs'][] = array(
  109. 'text' => $this->language->get('text_search'),
  110. 'href' => $this->url->link('product/search', $url)
  111. );
  112. }
  113. if (isset($this->request->get['product_id'])) {
  114. $product_id = (int)$this->request->get['product_id'];
  115. } else {
  116. $product_id = 0;
  117. }
  118. $this->load->model('catalog/product');
  119. $product_info = $this->model_catalog_product->getProduct($product_id);
  120. if ($product_info) {
  121. $url = '';
  122. if (isset($this->request->get['path'])) {
  123. $url .= '&path=' . $this->request->get['path'];
  124. }
  125. if (isset($this->request->get['filter'])) {
  126. $url .= '&filter=' . $this->request->get['filter'];
  127. }
  128. if (isset($this->request->get['manufacturer_id'])) {
  129. $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
  130. }
  131. if (isset($this->request->get['search'])) {
  132. $url .= '&search=' . $this->request->get['search'];
  133. }
  134. if (isset($this->request->get['tag'])) {
  135. $url .= '&tag=' . $this->request->get['tag'];
  136. }
  137. if (isset($this->request->get['description'])) {
  138. $url .= '&description=' . $this->request->get['description'];
  139. }
  140. if (isset($this->request->get['category_id'])) {
  141. $url .= '&category_id=' . $this->request->get['category_id'];
  142. }
  143. if (isset($this->request->get['sub_category'])) {
  144. $url .= '&sub_category=' . $this->request->get['sub_category'];
  145. }
  146. if (isset($this->request->get['sort'])) {
  147. $url .= '&sort=' . $this->request->get['sort'];
  148. }
  149. if (isset($this->request->get['order'])) {
  150. $url .= '&order=' . $this->request->get['order'];
  151. }
  152. if (isset($this->request->get['page'])) {
  153. $url .= '&page=' . $this->request->get['page'];
  154. }
  155. if (isset($this->request->get['limit'])) {
  156. $url .= '&limit=' . $this->request->get['limit'];
  157. }
  158. $this->data['breadcrumbs'][] = array(
  159. 'text' => $product_info['name'],
  160. 'href' => $this->url->link('product/product', $url . '&product_id=' . $this->request->get['product_id'])
  161. );
  162. $this->document->setTitle($product_info['name']);
  163. $this->document->setDescription($product_info['meta_description']);
  164. $this->document->setKeywords($product_info['meta_keyword']);
  165. $this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
  166. $this->document->addScript('catalog/view/javascript/jquery/tabs.js');
  167. $this->document->addScript('catalog/view/javascript/jquery/colorbox/jquery.colorbox-min.js');
  168. $this->document->addStyle('catalog/view/javascript/jquery/colorbox/colorbox.css');
  169. $this->data['heading_title'] = $product_info['name'];
  170. $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
  171. $this->data['text_login_write'] = sprintf($this->language->get('text_login_write'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
  172. $this->load->model('catalog/review');
  173. $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $product_info['reviews']);
  174. $this->data['product_id'] = $this->request->get['product_id'];
  175. $this->data['manufacturer'] = $product_info['manufacturer'];
  176. $this->data['manufacturers'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $product_info['manufacturer_id']);
  177. $this->data['model'] = $product_info['model'];
  178. $this->data['reward'] = $product_info['reward'];
  179. $this->data['points'] = $product_info['points'];
  180. if ($product_info['quantity'] <= 0) {
  181. $this->data['stock'] = $product_info['stock_status'];
  182. } elseif ($this->config->get('config_stock_display')) {
  183. $this->data['stock'] = $product_info['quantity'];
  184. } else {
  185. $this->data['stock'] = $this->language->get('text_instock');
  186. }
  187. $this->load->model('tool/image');
  188. if ($product_info['image']) {
  189. $this->data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
  190. } else {
  191. $this->data['popup'] = '';
  192. }
  193. if ($product_info['image']) {
  194. $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
  195. } else {
  196. $this->data['thumb'] = '';
  197. }
  198. $this->data['images'] = array();
  199. $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  200. foreach ($results as $result) {
  201. $this->data['images'][] = array(
  202. 'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
  203. 'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
  204. );
  205. }
  206. if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  207. $this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  208. } else {
  209. $this->data['price'] = false;
  210. }
  211. if ((float)$product_info['special']) {
  212. $this->data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  213. } else {
  214. $this->data['special'] = false;
  215. }
  216. if ($this->config->get('config_tax')) {
  217. $this->data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price']);
  218. } else {
  219. $this->data['tax'] = false;
  220. }
  221. $discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  222. $this->data['discounts'] = array();
  223. foreach ($discounts as $discount) {
  224. $this->data['discounts'][] = array(
  225. 'quantity' => $discount['quantity'],
  226. 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
  227. );
  228. }
  229. $this->data['options'] = array();
  230. foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
  231. $product_option_value_data = array();
  232. foreach ($option['product_option_value'] as $option_value) {
  233. if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
  234. if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
  235. $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false));
  236. } else {
  237. $price = false;
  238. }
  239. $product_option_value_data[] = array(
  240. 'product_option_value_id' => $option_value['product_option_value_id'],
  241. 'option_value_id' => $option_value['option_value_id'],
  242. 'name' => $option_value['name'],
  243. 'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
  244. 'price' => $price,
  245. 'price_prefix' => $option_value['price_prefix']
  246. );
  247. }
  248. }
  249. $this->data['options'][] = array(
  250. 'product_option_id' => $option['product_option_id'],
  251. 'product_option_value' => $product_option_value_data,
  252. 'option_id' => $option['option_id'],
  253. 'name' => $option['name'],
  254. 'type' => $option['type'],
  255. 'value' => $option['value'],
  256. 'required' => $option['required']
  257. );
  258. }
  259. if ($product_info['minimum']) {
  260. $this->data['minimum'] = $product_info['minimum'];
  261. } else {
  262. $this->data['minimum'] = 1;
  263. }
  264. $this->data['review_status'] = $this->config->get('config_review_status');
  265. if ($this->config->get('config_guest_review') || $this->customer->isLogged()) {
  266. $this->data['guest_review'] = true;
  267. } else {
  268. $this->data['guest_review'] = false;
  269. }
  270. if ($this->customer->isLogged()) {
  271. $this->data['customer_name'] = $this->customer->getFirstName() . '&nbsp;' . $this->customer->getLastName();
  272. } else {
  273. $this->data['customer_name'] = '';
  274. }
  275. $this->data['reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
  276. $this->data['rating'] = (int)$product_info['rating'];
  277. $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
  278. $this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
  279. $this->data['products'] = array();
  280. $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  281. foreach ($results as $result) {
  282. if ($result['image']) {
  283. $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
  284. } else {
  285. $image = false;
  286. }
  287. if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  288. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  289. } else {
  290. $price = false;
  291. }
  292. if ((float)$result['special']) {
  293. $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  294. } else {
  295. $special = false;
  296. }
  297. if ($this->config->get('config_review_status')) {
  298. $rating = (int)$result['rating'];
  299. } else {
  300. $rating = false;
  301. }
  302. $this->data['products'][] = array(
  303. 'product_id' => $result['product_id'],
  304. 'thumb' => $image,
  305. 'name' => $result['name'],
  306. 'price' => $price,
  307. 'special' => $special,
  308. 'rating' => $rating,
  309. 'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
  310. 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
  311. );
  312. }
  313. $this->data['tags'] = array();
  314. if ($product_info['tag']) {
  315. $tags = explode(',', $product_info['tag']);
  316. foreach ($tags as $tag) {
  317. $this->data['tags'][] = array(
  318. 'tag' => trim($tag),
  319. 'href' => $this->url->link('product/search', 'tag=' . trim($tag))
  320. );
  321. }
  322. }
  323. $this->model_catalog_product->updateViewed($this->request->get['product_id']);
  324. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
  325. $this->template = $this->config->get('config_template') . '/template/product/product.tpl';
  326. } else {
  327. $this->template = 'default/template/product/product.tpl';
  328. }
  329. $this->children = array(
  330. 'common/column_left',
  331. 'common/column_right',
  332. 'common/content_top',
  333. 'common/content_bottom',
  334. 'common/footer',
  335. 'common/header'
  336. );
  337. $this->response->setOutput($this->render());
  338. } else {
  339. $url = '';
  340. if (isset($this->request->get['path'])) {
  341. $url .= '&path=' . $this->request->get['path'];
  342. }
  343. if (isset($this->request->get['filter'])) {
  344. $url .= '&filter=' . $this->request->get['filter'];
  345. }
  346. if (isset($this->request->get['manufacturer_id'])) {
  347. $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
  348. }
  349. if (isset($this->request->get['search'])) {
  350. $url .= '&search=' . $this->request->get['search'];
  351. }
  352. if (isset($this->request->get['tag'])) {
  353. $url .= '&tag=' . $this->request->get['tag'];
  354. }
  355. if (isset($this->request->get['description'])) {
  356. $url .= '&description=' . $this->request->get['description'];
  357. }
  358. if (isset($this->request->get['category_id'])) {
  359. $url .= '&category_id=' . $this->request->get['category_id'];
  360. }
  361. if (isset($this->request->get['sub_category'])) {
  362. $url .= '&sub_category=' . $this->request->get['sub_category'];
  363. }
  364. if (isset($this->request->get['sort'])) {
  365. $url .= '&sort=' . $this->request->get['sort'];
  366. }
  367. if (isset($this->request->get['order'])) {
  368. $url .= '&order=' . $this->request->get['order'];
  369. }
  370. if (isset($this->request->get['page'])) {
  371. $url .= '&page=' . $this->request->get['page'];
  372. }
  373. if (isset($this->request->get['limit'])) {
  374. $url .= '&limit=' . $this->request->get['limit'];
  375. }
  376. $this->data['breadcrumbs'][] = array(
  377. 'text' => $this->language->get('text_error'),
  378. 'href' => $this->url->link('product/product', $url . '&product_id=' . $product_id)
  379. );
  380. $this->document->setTitle($this->language->get('text_error'));
  381. $this->data['heading_title'] = $this->language->get('text_error');
  382. $this->data['continue'] = $this->url->link('common/home');
  383. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  384. $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  385. } else {
  386. $this->template = 'default/template/error/not_found.tpl';
  387. }
  388. $this->children = array(
  389. 'common/column_left',
  390. 'common/column_right',
  391. 'common/content_top',
  392. 'common/content_bottom',
  393. 'common/footer',
  394. 'common/header'
  395. );
  396. $this->response->setOutput($this->render());
  397. }
  398. }
  399. public function review() {
  400. $this->data += $this->language->load('product/product');
  401. $this->load->model('catalog/review');
  402. if (isset($this->request->get['page'])) {
  403. $page = $this->request->get['page'];
  404. } else {
  405. $page = 1;
  406. }
  407. $this->data['reviews'] = array();
  408. $review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
  409. $results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], ($page - 1) * 5, 5);
  410. foreach ($results as $result) {
  411. $this->data['reviews'][] = array(
  412. 'author' => $result['author'],
  413. 'text' => $result['text'],
  414. 'rating' => (int)$result['rating'],
  415. 'reviews' => sprintf($this->language->get('text_reviews'), (int)$review_total),
  416. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  417. );
  418. }
  419. $pagination = new Pagination();
  420. $pagination->total = $review_total;
  421. $pagination->page = $page;
  422. $pagination->limit = 5;
  423. $pagination->text = $this->language->get('text_pagination');
  424. $pagination->url = $this->url->link('product/product/review', 'product_id=' . $this->request->get['product_id'] . '&page={page}');
  425. $this->data['pagination'] = $pagination->render();
  426. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/review.tpl')) {
  427. $this->template = $this->config->get('config_template') . '/template/product/review.tpl';
  428. } else {
  429. $this->template = 'default/template/product/review.tpl';
  430. }
  431. $this->response->setOutput($this->render());
  432. }
  433. public function write() {
  434. $this->data += $this->language->load('product/product');
  435. $this->load->model('catalog/review');
  436. $json = array();
  437. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  438. if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 25)) {
  439. $json['error'] = $this->language->get('error_name');
  440. }
  441. if ((utf8_strlen($this->request->post['text']) < 25) || (utf8_strlen($this->request->post['text']) > 1000)) {
  442. $json['error'] = $this->language->get('error_text');
  443. }
  444. if (empty($this->request->post['rating'])) {
  445. $json['error'] = $this->language->get('error_rating');
  446. }
  447. if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
  448. $json['error'] = $this->language->get('error_captcha');
  449. }
  450. if (!isset($json['error'])) {
  451. $this->model_catalog_review->addReview($this->request->get['product_id'], $this->request->post);
  452. $json['success'] = $this->language->get('text_success');
  453. }
  454. }
  455. $this->response->setOutput(json_encode($json));
  456. }
  457. public function captcha() {
  458. $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);
  459. $image = imagecreatetruecolor(150, 35);
  460. $width = imagesx($image);
  461. $height = imagesy($image);
  462. $black = imagecolorallocate($image, 0, 0, 0);
  463. $white = imagecolorallocate($image, 255, 255, 255);
  464. $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
  465. $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
  466. $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
  467. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  468. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
  469. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
  470. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
  471. imagefilledrectangle($image, 0, 0, $width, 0, $black);
  472. imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
  473. imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
  474. imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
  475. imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
  476. header('Content-type: image/jpeg');
  477. imagejpeg($image);
  478. imagedestroy($image);
  479. }
  480. public function upload() {
  481. $this->data += $this->language->load('product/product');
  482. $json = array();
  483. if (!empty($this->request->files['file']['name'])) {
  484. $filename = basename(preg_replace('/[^a-zA-Z0-9\.\-\s+]/', '', html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')));
  485. if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 64)) {
  486. $json['error'] = $this->language->get('error_filename');
  487. }
  488. // Allowed file extension types
  489. $allowed = array();
  490. $filetypes = explode("\n", $this->config->get('config_file_extension_allowed'));
  491. foreach ($filetypes as $filetype) {
  492. $allowed[] = trim($filetype);
  493. }
  494. if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
  495. $json['error'] = $this->language->get('error_filetype');
  496. }
  497. // Allowed file mime types
  498. $allowed = array();
  499. $filetypes = explode("\n", $this->config->get('config_file_mime_allowed'));
  500. foreach ($filetypes as $filetype) {
  501. $allowed[] = trim($filetype);
  502. }
  503. if (!in_array($this->request->files['file']['type'], $allowed)) {
  504. $json['error'] = $this->language->get('error_filetype');
  505. }
  506. if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  507. $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  508. }
  509. } else {
  510. $json['error'] = $this->language->get('error_upload');
  511. }
  512. if (!$json && is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  513. $file = basename($filename) . '.' . md5(mt_rand());
  514. // Hide the uploaded file name so people can not link to it directly.
  515. $json['file'] = $this->encryption->encrypt($file);
  516. move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  517. $json['success'] = $this->language->get('text_upload');
  518. }
  519. $this->response->setOutput(json_encode($json));
  520. }
  521. }
  522. ?>