[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 />
<input type="submit" value="upload" />
</form>
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>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<?php echo $upload_data['full_path']; ?>
<p><?php echo anchor('sell', 'Upload Another File!'); ?></p>
</div>
can anyone help me please?
it would be greatly appreciated
Thanks
Max