<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');



class Img_upload_ctrl extends user_index {
	
	public function __construct(){
		parent::__construct();
		$data = array();
	}
	
	public function upload_atachment(){		
		$image_info = getimagesize($_FILES["filename"]["tmp_name"]);

		$extension_val = explode($_FILES["filename"]["name"],'.');
		$file_name_val= $_FILES["filename"]["name"];

		$return = array('status'=>false,'e_type'=>'0');
		$return['i'] =$this->input->post('i');
		$file_name = $file_name_val;
		$filename = $this->input->post('filename');	
		$config['upload_path'] = 'public_html/attachments/';
		$config['allowed_types'] = '*';
		$config['max_size']	= '1000000';
		$config['max_width']  = '102400';
		$config['max_height']  = '76800';
		$config['file_name'] = $file_name;
		$config['overwrite'] = false;
		$this->load->library('upload', $config);
		if ( ! $this->upload->do_upload('filename')) {
			$return['error']= $this->upload->display_errors();
			echo json_encode($return);
		}else{
			$data = $this->upload->data();
			$return['file']= $data['file_name'];
			$config = array();
			//$config['image_library'] = 'gd2';
			$config['source_image']	= "public_html/attachments/".$data['file_name'];
			$config['new_image']	= "public_html/attachments/".$data['file_name'];
			$this->load->library('image_lib', $config); 
			$this->image_lib->resize();	
			$return['status']= true;				
			$return['e_type']= '2';	
			echo json_encode($return);
		}		
	}








}



?>