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

class Gallery_company extends CI_Model{
	var $gallery_path;
	var $gallery_path_url;

	function Gallery_company(){
		$this->gallery_path = realpath(FCPATH . "dist/companyProfile");
		$this->gallery_path_url = base_url() . 'dist/companyProfile';
	}

	function do_upload($cid){
			$config = array(
				'allowed_types' => 'jpg|png|gif',
				'upload_path' => $this->gallery_path,
				'file_name' => $cid . '.JPG',
				'overwrite' => TRUE
			);
			if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
				$this->load->library('upload', $config);
				$this->upload->do_upload();
				$image_data = $this->upload->data();
				$data = array(
					'uploadLogo' => $image_data['file_name']
				);
				$this->db->where('ID', $cid );
				$this->db->update('company', $data);

				$config = array(
					'source_image' => $image_data['full_path'],
					'new_image' => $this->gallery_path . '/companyProfile',
					'file_name' => $cid . '.JPG',
					'maintain_ratio' => true,
					'width' => 150,
					'height' => 150
				);

				$this->load->library('image_lib', $config);
				$this->image_lib->resize();

				return $image_data['file_name'];
			}else{
				return $this->input->post('companyfile');
			}
			// return $image_data['file_name'];
	}

}
