application/controllers/Uploader.php
//controller for the editing the  tourist spots
controller for the editing the  tourist spots
controller for the editing the tourist spots
public function editSpots(){
			$output = array('error' => false);
		   if(!empty($_FILES['file']['name'])){
			   $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['photo'] = $file['filename'];
				   $id = $_POST['id'];
				   $query = $this->dashboard_model->EditSpotEstablishmentPhoto($data,$id,'spots');
				   if($query != ""){
					   $output['error'] = false;
					   $output['message'] = 'Spot photo changed successfully';
				   }
				   else{
					   $output['error'] = true;
					   $output['message'] = 'File uploaded but not inserted to database';
				   }
			   }else{
				   $output['error'] = true;
				   $output['message'] = 'Cannot upload file';
			   }
		   }else{
			   $output['error'] = true;
			   $output['message'] = 'Cannot upload empty file';
		   }
		   echo json_encode($output);
			}
public function editSpots ( ) { $ output = array ( 'error' => false ) ; if ( ! empty ( $ _FILES [ 'file' ] [ 'name' ] ) ) { $ 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 [ 'photo' ] = $ file [ 'filename' ] ; $ id = $ _POST [ 'id' ] ; $ query = $ this -> dashboard_model -> EditSpotEstablishmentPhoto ( $ data , $ id , 'spots' ) ; if ( $ query != " " ) { $ output [ 'error' ] = false ; $ output [ 'message' ] = 'Spot photo changed successfully' ; } else { $ output [ 'error' ] = true ; $ output [ 'message' ] = 'File uploaded but not inserted to database' ; } } else { $ output [ 'error' ] = true ; $ output [ 'message' ] = 'Cannot upload file' ; } } else { $ output [ 'error' ] = true ; $ output [ 'message' ] = 'Cannot upload empty file' ; } echo json_encode ( $ output ) ; }
controller for the editing the  tourist spots
controller for the editing the tourist spots
//check if the filename is not empty //upload path of the file //allwoed MIME type of the file //check if true uploading the file to the path //call the function for editing //$output['message'] = $_FILES['file']['name'];