[eluser]Unknown[/eluser]
Is there an elegant way to include two or more <input type=file> . I have included my code for the controller below.
Currently, this code works aside from the form validation on the title field. I would like to figure out how to include form validation and a file upload.
Code:
<?php echo form_open_multipart('dashboard/do_upload/'. $section);?>
<?php
echo form_label('Upload Large Image here','orig_img');
?>
<input type="file" name="lrgimg" size="20" />
<br>
<?php
echo form_label('Upload Thumbnail Image here','orig_img');
?>
<input type="file" name="smallimg" size="20" />
<?php
echo "<br />";
echo form_hidden("section", $section );
echo "<br />";
echo form_label('What is the title of the Image','title_label');
echo form_error('title');
$data = array(
'name' => 'title',
'id' => 'title',
'maxlength' => '100',
'size' => '50',
'style' => 'width:30em',
);
echo "<br />";
echo form_input($data);
?>
<br /><br />
<input type="submit" value="upload" />
The controller
Code:
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '1800';
$config['max_height'] = '1800';
$this->load->library('upload', $config);
$this->load->library('form_validation');
$error = false;
if($this->upload->do_upload('smallimg'))
{
$tmpdata = $this->upload->data();
$thumb = $tmpdata['file_name'];
if(!$this->upload->do_upload('lrgimg'))
{
$error = $this->upload->display_errors();
$this->view_form($error,$section);
return;
}
$tmpdata = $this->upload->data();
$lrg = $tmpdata['file_name'];
//initialize data for transfer to success page and do final save file from data
$data['section'] = $section;
$data['title'] = "Dashboard - Successfully uploadeded file";
$title = $this->input->post('title');
$smalldestination = base_url("upload/" . $thumb);
$lrgdestination = base_url("upload/" . $lrg );
$this->home_model->save_temp_photo_data($lrg, $thumb);
$data['ulimgs'] = $this->home_model->get_uploaded_imgs();
$this->home_model->add_new_photo($lrgdestination,$smalldestination,$title,$section);
$this->load->view('dashboard/success',$data);
}
else
{
$error = $this->upload->display_errors();
$this->view_form($error,$section);
return;
}