[eluser]Elliot Haughin[/eluser]
[quote author="Kurai" date="1207923087"]Hi!
I've got this upload function:
Code:
function 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('backend/upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('backend/uploadok', $data);
}
}
Now, I would like not to get the "you did not select a file to upload" error when I load the view for the first time. But I don't want two different functions as in the example provided in the user guide. How can I do it?
Thank you![/quote]
Try changing it to this....
Code:
function upload()
{
if ($this->input->post('submit'))
{
$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('backend/upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('backend/uploadok', $data);
}
}
else
{
$this->load->view('backend/upload');
}
This assumes that your submit button is:
Code:
<input type="submit" name="submit" value="something or other" />