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



class Single_file_upload {



	private $ci ;

	

	public function __construct()

	{

		$this->ci = & get_instance();

		

	}

	

	public function do_upload($field_name = 'img',$max_size='512',$max_width='1024',$max_height='768')

	{

		$config = array(

				'upload_path' => './assets/images/',

				'allowed_types' => 'gif|jpg|jpeg' ,

				'max_size'	=> $max_size , // in Kb

				'max_width'  => $max_width ,

				'max_height'  => $max_height

				//'overwrite' => TRUE

				) ;

		

		$this->ci->load->library('upload', $config);



		if ( ! $this->ci->upload->do_upload($field_name))

		{

			return array('upload'=> 0, 'errors' => $this->ci->upload->display_errors() );

		}

		else

		{

			$upload_data = $this->ci->upload->data() ;



			return array('upload'=> 1, 'filename' => $upload_data['file_name'] );

		}

	}

	



}

