Welcome Guest, Not a member yet? Register   Sign In
How do i insert a uploaded image's path to the database?


I can upload an image to my site but i am having real trouble getting the path of the image into my database...?

this is my controller


class Sell extends CI_Controller
    function __construct()
        $this->load->helper(array('form', 'url'));
    function index()
        $this->load->view('sell_view', 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('sell_view', $error);
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('listed_view', $data);

and my model...

class Sell_model extends CI_Model
    function getPropertyType()
        $rows = $this->db->select('id, name')
        foreach ($rows as $row)
            $property_type[$row->id] = $row->name;
        return $property_type;
    function listProperty()
        $data = array($this->upload->data());
        $insert = array(
        $this->db->insert('sell_property', $insert);

and my view

<?php echo $error;?>

    <?php echo form_open_multipart('sell/do_upload');?>

        <input type="file" name="userfile" size="20" />

        <br /><br />

        &lt;input type="submit" value="upload" /&gt;


and the other view.
which manages to show the path of the image i just can't understand why it wont let me insert it into the database!?!?!?

<div id="container">
    your property has been added
    <h3>Your file was successfully uploaded!</h3>

        &lt;?php foreach ($upload_data as $item => $value):?&gt;
            <li>&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;</li>
        &lt;?php endforeach; ?&gt;
    &lt;?php echo $upload_data['full_path']; ?&gt;

    <p>&lt;?php echo anchor('sell', 'Upload Another File!'); ?&gt;</p>

can anyone help me please?

it would be greatly appreciated



You don't have $data['full_path'] as part of your insert statement anywhere.

The file loading will take care of itself, but if you want its info stored in the db, you need to pass it there



all i need to put?!

Ah, I missed that, sorry.

Then use the standard debugging techniques and see where it is going wrong.

you can start with:


to see what your insert statement looks like, and if the value is there. Also, share any error messages.

"can't get it into the database" is rather vague for us to try to help you. could be your table schema, for example

how about this..
$results = $this->upload->data();


'images'=> $results['file_name']

Theme © iAndrew 2016 - Forum software by © MyBB