[eluser]Unknown[/eluser]
Hello, I have a form and giving the user an option to upload image. It works great as long as the user selects an image. But if they dont select an image it gives error.
I have a default image given to the field in the database. So if none is selected it uses the default image.
But how can I have it so it does not give me an error when no image is selected, Though I want to keep it so it still shows errors if file is too big..ect..
here is code but not sure what all you would need to look at , if more just let me know.
Controller
==============
Code:
//this sets up the image upload data
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('userfile'))
{
$data['error'] = array('error' => $this->upload->display_errors());
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$data['id'] = $session_data['id'];
$this->load->view('layout/header');
$this->load->view('layout/logo');
$this->load->view('layout/banner');
$this->load->view('car/basic_view',$data);
$this->load->view('layout/footer');
}else{//no errors, stores data about image
$pic = $this->upload->data();
}
VIEW PAGE
================
Code:
<?php // Change the css classes to suit your needs
$attributes = array('class' => 'text', 'id' => '');
echo form_open_multipart('profile/add/basic', $attributes);
?>
<!----ADD AN IMAGE------------>
<table width="731" align="center" border="0" cellspacing="16" cellpadding="0">
<tr>
<label for="image"> Add your image</label>
<td>
<input type="file" name="userfile" size="20" />
<?php echo form_submit( 'submit', 'Submit'); ?>
<?php echo form_close(); ?>
</td>
</tr>
</table>
Thanks for any help you can offer. also the default image is uploads/default.jpg