Welcome Guest, Not a member yet? Register   Sign In
ho to image upload and save it in data base?
#1

[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 advancSmile






?>
#2

[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);  
                               $this->image_lib->resize();
                               $image_name=$image_data['file_name'];
                     $data=array(
                        'nom_path'=>$image_name,
                        'identifiant_annonce'=>$identifannonce
                        
                            );
                            
                            
                          
                            
                            $this->annoncemodel->add_image($data);

and in model annoncemodel (image is my table for image

Code:
public function add_image($data)
       {
           $this->db->insert('image', $data );
          
       }
#3

[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??....




Theme © iAndrew 2016 - Forum software by © MyBB