Index.php 2.23 KB
<?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;
	}
}