[eluser]Unknown[/eluser]
Brand new to code igniter, but I'm really enjoying how easily you can just jump right in.
I'm working on a project where I need to upload a file and save the file name to a database along with some metadata from drop downs.
I have the form working in so far as it uploads the file and creates the record, but doesn't seem to get the path name right.
In the Controller:
Code:
public function submit()
{
$this->load->model('admin_model');
if($this->_submit_validate() == FALSE)
{
$this->add();
return;
}
else
{
$this->admin_model->do_upload();
$region = new Region();
$region->plane = $this->input->post('plane');
$region->region = $this->input->post('region');
$region->save();
$p = new Photo();
$p->photo_path = $this->input->post('userfile');
$p->Region = $region;
$p->save();
}
redirect('/admin/add/');
}
private function _submit_validate()
{
$this->form_validation->set_rules('plane', 'Plane', 'required');
$this->form_validation->set_rules('region', 'Region','required');
return $this->form_validation->run();
}
In the model:
Code:
<?php
class Admin_model extends Model
{
var $gallery_path;
function Admin_model()
{
parent::Model();
//$this->gallery_path = realpath(APPPATH . '../images');//Couldn't get this working for whatever reason
$this->gallery_path = "C:\\wamp\\localpath\\images\\";
}
function do_upload()
{
$config = array(
'allowed_types' => 'jpg|jpeg|png|gif',
'upload_path' => $this->gallery_path
);
$this->load->library('upload', $config);
$this->upload->do_upload();
}
}
So really, 2 questions right now.
1. When I submit a file it uploads correctly and creates a new record and a new region tag for the photo, however the photopath name in the db is saved as 'x^' (I do have the doctrine model set up as a gzip field, but don't think this should matter?)
2. How can I move all the validation to the model and have it validate the upload and the form and THEN return all the errors.
Many thanks. CI is a lot of fun.