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 addSpot(){
			$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['name'] = $_POST['name'];
					$data['municipality'] = $_POST['municipality'];
					$data['district'] = $_POST['district'];
					$data['category'] = $_POST['category'];
					$data['photo'] = $file['filename'];
					$query = $this->dashboard_model->Add($data,'spots');
					if($query != ""){
						$output['error'] = false;
						$output['message'] = 'Spot added 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 addSpot ( ) { $ 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 [ 'name' ] = $ _POST [ 'name' ] ; $ data [ 'municipality' ] = $ _POST [ 'municipality' ] ; $ data [ 'district' ] = $ _POST [ 'district' ] ; $ data [ 'category' ] = $ _POST [ 'category' ] ; $ data [ 'photo' ] = $ file [ 'filename' ] ; $ query = $ this -> dashboard_model -> Add ( $ data , 'spots' ) ; if ( $ query != " " ) { $ output [ 'error' ] = false ; $ output [ 'message' ] = 'Spot added 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 ) ; }
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 //allwoed 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'];