1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
# SM Shop4u - Version 1.0.0
# Copyright (c) 2016 YouTech Company. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: YouTech Company
# Websites: http://www.magentech.com
-------------------------------------------------------------------------*/
namespace Sm\Shop4u\Controller\Index;
use \Magento\Framework\App\Action\Context;
use \Magento\Framework\View\Result\PageFactory;
class Index extends \Magento\Framework\App\Action\Action {
/** @var \Magento\Framework\View\Result\Page */
protected $resultPageFactory;
/** * @param \Magento\Framework\App\Action\Context $context */
public function __construct(Context $context, PageFactory $resultPageFactory) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Blog Index, shows a list of recent blog posts.
*
* @return \Magento\Framework\View\Result\PageFactory
*/
public function execute()
{
try {
if (isset($_FILES['file'])) {
$directory = 'author';
if (isset($_POST['directory'])) {
$directory = $_POST['directory'];
}
$imageId = $_POST['image_identifire'] ?? 0;
$response = array('status' => FALSE, 'uri' => '', 'message' => '');
$target_dir = "/var/www/coconva/pub/media/tmp/";
$file_name = "d-" . $imageId . "_w-" . $_POST['image_width'] . "_h-" . $_POST['image_heigth'] . "_" . basename($_FILES["file"]["name"]);
$uri = "http://coconva.incaendo.com/pub/media/tmp/" . $file_name;
$target_file = $target_dir . $file_name;
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
$response['uri'] = $uri;
$response['status'] = TRUE;
}
// } else {
// $response['message'] = 'We are sorry, we do not support that file type. Please use either png, gif, jpg, jpeg file.';
// }
} else {
$response['message'] = "We are sorry, there was an error uploading your.";
}
echo json_encode($response);
echo "<script> window.parent.imageHolder". $imageId ."('" . @$response['status'] . "', '" . @$response['message'] . "', '" . @$response['uri'] . "'); </script>";
die;
} catch (Exception $e) {
// LOG
}
die;
}
}