application/controllers/Common.php
/*Function for upload shortlisted property image */
Function for upload shortlisted property image
Function for upload shortlisted property image
public function handle_commentFile_upload($comment) {
		$image = array();
		$fileType = array();
		foreach ($comment as $key) {
			$image[] = $key['commentFile'];
			$fileType[] = $key['fileType'];
		}
		for($i=0;$i<sizeof($image);$i++)
		{
			if($image[$i])
			{
			    $temp_file_path = tempnam(sys_get_temp_dir(), 'androidtempimage'); 
				file_put_contents($temp_file_path, base64_decode($image[$i]));
				if ($fileType[$i] == 'image') {			
					$image_info = getimagesize($temp_file_path);		
					$ext = preg_replace('!\w+/!', '', $image_info['mime']);
				}else{				
					$finfo = new finfo(FILEINFO_MIME);
					$ext = $finfo->buffer(base64_decode($image[$i])) . "\n";			
					$ext = preg_replace('!\w+/!', '', $ext);
					$ext = substr($ext, 0, strpos($ext, ";"));
				}
				$_FILES['userfile'] = array(
				     'name' =>  $this->clean(do_hash(rand() . time() . rand(). uniqid())).'.'.$ext,
				     'tmp_name' => $temp_file_path,
				     'size'  => filesize($temp_file_path),
				     'error' => UPLOAD_ERR_OK,
				     'type'  =>  $ext,
				);
				if($fileType[$i] == 'image'){
					$config['upload_path'] = './uploads/comment/image';	    
			    	$config['allowed_types'] = 'gif|jpg|jpeg|png';
			    	$folder_path = "image"; 
				}
				if($fileType[$i] == 'audio'){
					$config['upload_path'] = './uploads/comment/audio';	   
					$config['allowed_types'] = '*';
			    	$folder_path = "audio";
				}
			    $config['max_size'] = '1000000';
			    $config['remove_spaces'] = TRUE;
			    $config['encrypt_name'] = TRUE;
			    $this->load->library('upload', $config);
			    $this->upload->initialize($config);
			    if($this->upload->do_upload_rest('userfile', true)) {
			        $arr_image_info = $this->upload->data();
			        if (!isset($_POST['commentFile1'.$i])) {
			        	$_POST['commentFile1'.$i] = '/uploads/comment/'.$folder_path.'/'.$arr_image_info['file_name'];
			        }			    
			    }else{
					return false;
			    }
		   }else{
		   		return true;
		   }
		}
		return true;
	}
public function handle_commentFile_upload ( $ comment ) { $ image = array ( ) ; $ fileType = array ( ) ; foreach ( $ comment as $ key ) { $ image [ ] = $ key [ 'commentFile' ] ; $ fileType [ ] = $ key [ 'fileType' ] ; } for ( $ i = 0 ; $ i < sizeof ( $ image ) ; $ i ++ ) { if ( $ image [ $ i ] ) { $ temp_file_path = tempnam ( sys_get_temp_dir ( ) , 'androidtempimage' ) ; file_put_contents ( $ temp_file_path , base64_decode ( $ image [ $ i ] ) ) ; if ( $ fileType [ $ i ] == 'image' ) { $ image_info = getimagesize ( $ temp_file_path ) ; $ ext = preg_replace ( '!\w+/!' , '' , $ image_info [ 'mime' ] ) ; } else { $ finfo = new finfo ( FILEINFO_MIME ) ; $ ext = $ finfo -> buffer ( base64_decode ( $ image [ $ i ] ) ) . " \n " ; $ ext = preg_replace ( '!\w+/!' , '' , $ ext ) ; $ ext = substr ( $ ext , 0 , strpos ( $ ext , " ; " ) ) ; } $ _FILES [ 'userfile' ] = array ( 'name' => $ this -> clean ( do_hash ( rand ( ) . time ( ) . rand ( ) . uniqid ( ) ) ) . '.' . $ ext , 'tmp_name' => $ temp_file_path , 'size' => filesize ( $ temp_file_path ) , 'error' => UPLOAD_ERR_OK , 'type' => $ ext , ) ; if ( $ fileType [ $ i ] == 'image' ) { $ config [ 'upload_path' ] = './uploads/comment/image' ; $ config [ 'allowed_types' ] = 'gif|jpg|jpeg|png' ; $ folder_path = " image " ; } if ( $ fileType [ $ i ] == 'audio' ) { $ config [ 'upload_path' ] = './uploads/comment/audio' ; $ config [ 'allowed_types' ] = '*' ; $ folder_path = " audio " ; } $ config [ 'max_size' ] = '1000000' ; $ config [ 'remove_spaces' ] = TRUE ; $ config [ 'encrypt_name' ] = TRUE ; $ this -> load -> library ( 'upload' , $ config ) ; $ this -> upload -> initialize ( $ config ) ; if ( $ this -> upload -> do_upload_rest ( 'userfile' , true ) ) { $ arr_image_info = $ this -> upload -> data ( ) ; if ( ! isset ( $ _POST [ 'commentFile1' . $ i ] ) ) { $ _POST [ 'commentFile1' . $ i ] = '/uploads/comment/' . $ folder_path . '/' . $ arr_image_info [ 'file_name' ] ; } } else { return false ; } } else { return true ; } } return true ; }
Function for upload shortlisted property image
Function for upload shortlisted property image
// might not work on some systems, specify your temp path if system temp dir is not writeable //extension of file object //print_r($finfo);exit; //extension of file object //echo $ext;exit; //extension of file object //'name' => preg_replace('!\w+/!', '', $image_info['mime']), //$config['allowed_types'] = 'mp3|audio/mpeg|audio/x-wav|audio/x-aiff|application/ogg|application/octet-stream';  //$config['allowed_types'] = 'audio/mpeg|audio/x-wav|audio/x-aiff|audio/wav|audio/vnd.dlna.adts|application/ogg|application/octet-stream|application/force-download'; //return true; //for