i making module user upload image details database not working not validations showing created uploads directory images
controller:
public function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '1024'; $config['max_width'] = '1024'; $config['max_height'] = '1024'; $config['new_image'] = './uploads/'; $config['overwrite'] = true; $this->load->library('upload', $config); $this->form_validation->set_rules('type', 'type', 'required'); $this->form_validation->set_rules('school', 'school', 'required'); $this->form_validation->set_rules('email', 'email', 'required|valid_email'); if (!$this->upload->do_upload() || !$this->form_validation->run()) { $error = array('error' => $this->upload->display_errors()); redirect('user/payment'); } else { $data = $this->upload->data(); $this->thumb($data); $file = array( 'img_name' => $data['raw_name'], 'thumb_name' => $data['raw_name'] . '_thumb', 'ext' => $data['file_ext'], 'type' => $this->input->post('type'), 'school' => $this->input->post('school'), 'email' => $this->input->post('email'), ); $data = array('upload_data' => $this->upload->data()); $this->user_model->add_image($file); // redirect('user/home_register'); $this->load->view('user/upload_success'); } } public function thumb($data) { $config['image_library'] = 'gd2'; $config['source_image'] = $data['full_path']; $config['create_thumb'] = true; $config['maintain_ratio'] = true; $config['width'] = 275; $config['height'] = 250; $config['new_image'] = './thumbs/'; $this->load->library('image_lib', $config); $this->image_lib->resize(); }
view:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>technofest - user</title> <?php echo link_tag('css/bootstrap.min.css'); ?> <?php echo link_tag('jumbotron-narrow.css'); ?> </head> <body> <br> <div align="center"> </div> <br> <div class ="container"> <ul class="nav nav-pills nav-justified"> <li role="presentation"><a href="<?php echo base_url() . 'user/index';?>">home</a></li> <li role="presentation" ><a href="<?php echo base_url() . 'user/about';?>">about</a></li> <li role="presentation"><a href="<?php echo base_url() . 'user/contact';?>">contact</a></li> <li role="presentation" class="active" ><a href="<?php echo base_url() . 'user/home_register';?>">register</a></li> </ul> </div> <br> <br> <div> <?php echo form_open_multipart('user/do_upload'); ?> <?php if (validation_errors()): ?> <div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">close</span></button> <?php echo validation_errors(); ?> </div> <?php endif ?> <div class ="container center-block"> <div class="jumbotron"> <div class ="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">payment</h3> </div> <div class="panel-body"> <div class="form-group"> <div class="row"> <label class="col-sm-2 control-label">type:</label> <input type="radio" id="indiv" name="regtype" value="<?php echo set_value('type'); ?>" id='1'<?php echo set_radio('type','individual', true)?>/> invidivual <input id="bat" type="radio" name="regtype" value="<?php echo set_value('type'); ?>" id='2' <?php echo set_radio('type','batch')?>/> batch <?php echo form_error('type'); ?> <br><br> <label class="col-sm-2 control-label">payment for:</label> </div> </div> <div class="form-group"> <div class="row"> <label class="col-sm-2 control-label">school:</label> <div class="col-sm-5"> <input type="text" class="form-control" placeholder="enter school name" name="school" value="<?php echo set_value('school'); ?>"> </div> </div> </div> <?php echo form_error('school'); ?> <div class="form-group"> <div class="row"> <label class="col-sm-2 control-label">email:</label> <div class="col-sm-5"> <input type="text" class="form-control" placeholder="enter email" name="email" value="<?php echo set_value('email'); ?>"> </div> </div> </div> <?php echo form_error('email'); ?> <input type="file" id="imginp" name = "pic" required width = "10px"> <div class="col-sm-offset-2 col-sm-10"> <button type="button, submit" class="btn btn-primary " style="border-radius: 0;"> upload </button> <a href="<?php echo base_url().'user/home_register';?>" type="button" class="btn btn-primary">back</a> </div> <?php echo form_close() ?> </div> </div> </div> <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> </body> </html>
model
function add_image($data) { $this->db->set('payment_date', 'now()', false); $this->db->insert('payment', $data); }
i have 8 fields in db id(auto increment),payment_data,type,school,email,img_name,thumb_name , ext
try adding pic field name
$this->upload->do_upload('pic')
and change raw name
file_name
Comments
Post a Comment