public function uplodeimage()
 {
     if (isset($_FILES) && $_FILES['image']['name'] != '') {
         $config['upload_path'] = DOC_ROOT_CLASSIFIED_AD;
         $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
         $config['file_name'] = time() . rand(1, 999);
         $this->load->library('upload', $config);
         $path_parts = pathinfo($_FILES["image"]["name"]);
         $imgName = $config['file_name'] . '.' . $path_parts['extension'];
         //$imgName = $config['file_name'];
         if (!$this->upload->do_upload('image')) {
             $error = $this->upload->display_errors();
         }
         dowatermark($config['upload_path'] . $imgName);
         if ($error != "") {
             $messages['imgname'] = $error;
             $result['status'] = "204";
             $result['message'] = $error;
             $result['data'] = $messages;
             return $result;
         }
         $messages['image_name'] = $imgName;
         $messages['ad_thumb_image'] = image(clad_img_path() . $imgName, 'm_thumb');
         $messages['ad_main_image'] = clad_img_path() . $imgName;
         $result['status'] = "200";
         $result['message'] = "Image successfuly completed";
         $result['data'] = $messages;
         return $result;
     } else {
         $result['status'] = "204";
         $result['message'] = "Please enter valid data";
         $result['data'] = array();
     }
 }
 public function fileupload()
 {
     $file_name = "";
     $error = "";
     $post = $this->input->post();
     if ($_FILES['file']['name'] != '' && $_FILES['file']['error'] == 0) {
         if (!is_dir('./uploads/ad/tmp/')) {
             @mkdir('./uploads/ad/tmp/');
         }
         $config['upload_path'] = './uploads/ad/tmp/';
         $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
         $file_name_arr = explode('.', $_FILES['file']['name']);
         $file_name_arr = array_reverse($file_name_arr);
         $file_extension = $file_name_arr[0];
         $file_name = $config['file_name'] = rand() . "-" . time() . "." . $file_extension;
         $this->load->library('upload', $config);
         if (!$this->upload->do_upload('file')) {
             $e_flag = 1;
             $error = $this->upload->display_errors();
         }
         $file_name = "tmp/" . $file_name;
         /* Watermark */
         /*$this->load->library('image_lib');
         		 $config['source_image'] = $config['upload_path'].$config['file_name'];
         		 $config['wm_text']  = WATERMARK;
         		 $config['wm_type'] = 'text';
         		 $config['wm_font_size'] = '80';
         		$config['wm_opacity']       = 50;
         		$config['wm_vrt_alignment'] = 'bottom';
         		$config['wm_hor_alignment'] = 'right';
         		
         		$this->image_lib->initialize($config);
         		
         		if (!$this->image_lib->watermark()) {
         			$e_flag = 1;
         			$error = $this->image_lib->display_errors();
         		}*/
         dowatermark($config['upload_path'] . $config['file_name']);
         if ($error != "") {
             echo "Error:" . $error;
         } else {
             echo '{"id":"' . $file_name . '","path":"' . base_url() . "uploads/ad/" . $file_name . '"}';
         }
         exit;
     } else {
         echo "Error: File not uploaded to server.";
     }
 }
function processimg_new($files)
{
    $CI =& get_instance();
    $config = array();
    $config['upload_path'] = DOC_ROOT_CLASSIFIED_AD . 'tmp/';
    $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
    $CI->load->library('upload', $config);
    $fileParam = array('name', 'type', 'tmp_name', 'error', 'size');
    //for ($i = 0; $i < count($files['name']); $i++) {
    $i = 0;
    $extArr = explode('.', $files['name'][$i]);
    $ext = array_pop($extArr);
    $imgName = time() . rand(1, 999) . '.' . $ext;
    //$imgName = getNewImageName($files['name'][$i]);
    $filearr = $_FILES = array();
    foreach ($fileParam as $j) {
        $_FILES['images'][$j] = $files[$j][$i];
    }
    $_FILES['images']['name'] = $imgName;
    //$_FILES['images'] = $files;
    $error = '';
    //pr($_FILES,1);
    if (!$CI->upload->do_upload('images')) {
        $error = $CI->upload->display_errors();
    }
    $ret = array();
    if ($error != "") {
        $ret["error"] = $error;
        //die;
    } else {
        dowatermark($config['upload_path'] . $imgName);
        $ret["file"] = $imgName;
    }
    echo json_encode($ret);
    //}
}