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

[eluser]maxrosecollins[/eluser]
Hi,

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

Code:
<?php

class Sell extends CI_Controller
{    
    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {
        $this->load->view('sell_view', array('error' => ' ' ));
    }

    function do_upload()
    {
        $this->load->model('sell_model');
        
        $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);
        }
        else
        {
            $this->sell_model->listProperty();
            
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('listed_view', $data);
        }
        
        
    }    
}


and my model...


Code:
<?php
class Sell_model extends CI_Model
{
    function getPropertyType()
    {
        $rows = $this->db->select('id, name')
            ->from('property_type')
            ->get()->result();    
        foreach ($rows as $row)
        {
            $property_type[$row->id] = $row->name;
        }
        return $property_type;
    }
    
    function listProperty()
    {
        $data = array($this->upload->data());
        
        $insert = array(
            'property_type_id'=>$this->input->post('property_type'),
               'bedrooms'=>$this->input->post('bedrooms'),
               'price'=>$this->input->post('price'),
               'images'=>$data['full_path'],
               'building_name'=>$this->input->post('building_name'),
               'road'=>$this->input->post('road'),
               'town'=>$this->input->post('town'),
               'county'=>$this->input->post('county'),
               'postcode'=>$this->input->post('postcode'),
               'tenure_type_id'=>$this->input->post('tenure'),
               'features'=>$this->input->post('features'),
               'description'=>$this->input->post('description'),
               'bathrooms'=>$this->input->post('bathrooms'),
               'seller_id'=>$this->input->post('seller_id')
        );
        $this->db->insert('sell_property', $insert);
    }
}



and my view


Code:
<?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;

&lt;/form&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!?!?!?

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

    <ul>
        &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;
    </ul>
    
    &lt;?php echo $upload_data['full_path']; ?&gt;

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

can anyone help me please?

it would be greatly appreciated

Thanks

Max


Messages In This Thread
How do i insert a uploaded image's path to the database? - by El Forum - 07-14-2011, 11:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB