application/controllers/Uploader.php
//inserting new to spot to the database
inserting new to spot to the database
inserting new to spot to the database
public function addEstablishment(){
	    $output = array('error' => false);
        if(!empty($_FILES['file']['name'])){
			if($_POST['name'] != "" && $_POST['location'] != "" && $_POST['rates'] != "" && $_POST['contact'] != "" && $_POST['other'] != ""){
						 $config['upload_path'] = 'assets/images/';
						 $config['file_name'] = $_FILES['file']['name'];
						 $config['allowed_types'] = 'gif|jpg|png|jpeg';
						 $this->load->library('upload', $config);
						 $this->upload->initialize($config);
						 if($this->upload->do_upload('file')){
							 $uploadData = $this->upload->data();
							 $filename = $uploadData['file_name'];
							 $file['filename'] = $filename;
							 $data['name'] = $_POST['name'];
							 $data['location'] = $_POST['location'];
							 $data['rates'] = $_POST['rates'];
							 $data['contact'] = $_POST['contact'];
							 $data['other'] = $_POST['other'];
							 $data['photo'] = $file['filename'];
							 $query = $this->dashboard_model->AddEstablishment($data,'establishment');
							 if($query != "Error"){
								 $datas['photo'] = $file['filename'];
								 $datas['establishment_id'] = $query;
								 $result = $this->dashboard_model->AddEstabPhoto($datas, "establishment_photo");
								 if($result != "Error"){
									$output['error'] = false;
								    $output['message'] = $result;
								 }else{
									$output['error'] = false;
								    $output['message'] = $result;
								 }
							 }
							 else{
								 $output['error'] = true;
								 $output['message'] = 'Photo uploaded but not inserted to database';
							 }
						 }else{
							 $output['error'] = true;
							 $output['message'] = 'Cannot upload photo';
						 }
			}else{
				 		$output['message'] = "All fields must be filled up!";
		 	}
        }else{
        	$output['error'] = true;
			$output['message'] = 'Cannot upload empty photo';
        }
        echo json_encode($output);
	 	}
public function addEstablishment ( ) { $ output = array ( 'error' => false ) ; if ( ! empty ( $ _FILES [ 'file' ] [ 'name' ] ) ) { if ( $ _POST [ 'name' ] != " " && $ _POST [ 'location' ] != " " && $ _POST [ 'rates' ] != " " && $ _POST [ 'contact' ] != " " && $ _POST [ 'other' ] != " " ) { $ config [ 'upload_path' ] = 'assets/images/' ; $ config [ 'file_name' ] = $ _FILES [ 'file' ] [ 'name' ] ; $ config [ 'allowed_types' ] = 'gif|jpg|png|jpeg' ; $ this -> load -> library ( 'upload' , $ config ) ; $ this -> upload -> initialize ( $ config ) ; if ( $ this -> upload -> do_upload ( 'file' ) ) { $ uploadData = $ this -> upload -> data ( ) ; $ filename = $ uploadData [ 'file_name' ] ; $ file [ 'filename' ] = $ filename ; $ data [ 'name' ] = $ _POST [ 'name' ] ; $ data [ 'location' ] = $ _POST [ 'location' ] ; $ data [ 'rates' ] = $ _POST [ 'rates' ] ; $ data [ 'contact' ] = $ _POST [ 'contact' ] ; $ data [ 'other' ] = $ _POST [ 'other' ] ; $ data [ 'photo' ] = $ file [ 'filename' ] ; $ query = $ this -> dashboard_model -> AddEstablishment ( $ data , 'establishment' ) ; if ( $ query != " Error " ) { $ datas [ 'photo' ] = $ file [ 'filename' ] ; $ datas [ 'establishment_id' ] = $ query ; $ result = $ this -> dashboard_model -> AddEstabPhoto ( $ datas , " establishment_photo " ) ; if ( $ result != " Error " ) { $ output [ 'error' ] = false ; $ output [ 'message' ] = $ result ; } else { $ output [ 'error' ] = false ; $ output [ 'message' ] = $ result ; } } else { $ output [ 'error' ] = true ; $ output [ 'message' ] = 'Photo uploaded but not inserted to database' ; } } else { $ output [ 'error' ] = true ; $ output [ 'message' ] = 'Cannot upload photo' ; } } else { $ output [ 'message' ] = " All fields must be filled up! " ; } } else { $ output [ 'error' ] = true ; $ output [ 'message' ] = 'Cannot upload empty photo' ; } echo json_encode ( $ output ) ; }
inserting new to spot to the database
inserting new to spot to the database
//check if the filename is not empty //upload path of the file //allowed MIME type of the file //check if true uploading the file to the path //get the data from the users input //call the add function in the model	 //check if the return of query is not empty //$output['message'] = $_FILES['file']['name'];