![]() |
ho to image upload and save it in data base? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: ho to image upload and save it in data base? (/showthread.php?tid=50280) |
ho to image upload and save it in data base? - El Forum - 03-21-2012 [eluser]meer[/eluser] hi every one , im new to codeigniter i wants to uplad a image and save its file name into the data base i tried alott bt didnt find out the way im using the folling codes Controller <?php class Upload extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); } function index() { $this->load->view('upload_form', array('error' => ' ' )); } function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $error); } else { $filename = $data['upload_data']['file_name']; $file_data = file_get_contents($data['upload_data']['file_name']); $this->load->model('form_model'); $this->form_model->add_data($filename, $file_data, 'ID1'); $data = array('upload_data' => $this->upload->data()); $this->load->view('upload_success', $data); } } } ?> Model <?php class Form_model extends CI_Model{ function form_model() { parent::Model(); } function add_data($filename, $filedata, $post_id) { //(images)...its my table name $this->db->query("INSERT INTO images SET file_data='$filedata', filename='$filename', postid='$post_id'"); } } /////////////////////////////// on execution its showing the blank page please sum one help me.......... Thanks in advanc ![]() ?> ho to image upload and save it in data base? - El Forum - 03-21-2012 [eluser]ludo31[/eluser] Why you don't use db->insert in model in my controller (it's not a full code ) Code: $this->load->library('image_lib',$config); and in model annoncemodel (image is my table for image Code: public function add_image($data) ho to image upload and save it in data base? - El Forum - 03-21-2012 [eluser]meer[/eluser] thanks for ur rep i modified your code into my model but itss giving the errors Message: Undefined variable: image_data Message: Undefined variable: identifannonce Message: Undefined property: Upload::$form_model what about these??.... |