[eluser]ICS4U1[/eluser]
Hello, I am trying to upload an image path to a database and cannot figure it out.
Code:
//data model @@@@@@@@@@@@@
function getAll() {
$q = $this->db->get('data');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function add_record($data)
{
$this->db->insert('data', $data);
return;
}
//IMAGE @@@@@@@@@@@@@@@@@@@@@
var $gallery_path;
var $gallery_path_url;
function data_model() {
$this->gallery_path = realpath(APPPATH . '../upload');
$this->gallery_path_url = 'http://localhost/OscarProject/upload/';
}
function do_upload() {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path,
'max_size' => 2000
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '/thumbs',
'maintain_ratio' => true,
'width' => 150,
'height' => 100
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
function get_images() {
$files = scandir($this->gallery_path);
$files = array_diff($files, array('.', '..', 'thumbs'));
$temp = array();
foreach ($files as $file) {
$temp []= array (
'url' => $this->gallery_path_url . $file,
'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
);
$images = $temp[0];
}
return $images;
}
CONTROLLER
Code:
// CONTROLLER
function create()
{
$this->load->model('data_model');
$data = array(
'item' => $this->input->post('item'),
'price' => $this->input->post('price')/*,
'image' => $this->input->post('image')*/
);
if ($this->input->post('temp')) {
$this->data_model->do_upload();
}
$data['images'] = $this->data_model->get_images();
$this->load->model('data_model');
$this->data_model->add_record($data);
$this->crud();
}
VIEW
Code:
// VIEW
</tr>
<td> <?php echo $row ->item;?></td>
<td> <?php echo $row ->price;?></td>
<td><?php echo anchor("site/delete/$row->id", "Delete"); ?></td>
<td><?php echo anchor("site/update/$row->id", "Update"); ?></td>
<td><a><img src="<?php echo base_url().$row->images;?>"></a></td>
</tr>
<?php endforeach ;?>
</table>
<?php endif; ?>
</div>
<h2>Create</h2>
<?php echo form_open('site/create');?>
<p>
<label for="title">Item:</label>
<input type="text" name="item" id="item" />
</p>
<p>
<label for="content">Price:</label>
<input type="text" name="price" id="price" />
</p>
<p>
<label for="content">Image:</label>