Magento Themes and Magento Extensions

Codeigniter Multiple File Upload function

Share

in magento An easy function to upload two image by a html form.

?
function save_images()
{
$html = '';
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|JPEG|jpeg|PNG|GIF|JPG';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('pic1'))
{
$html .= $this->upload->display_errors();
$html .='<br />File Not Uploaded';
$upload_data['file_name']='nopic.png';
}
else
{
$upload_data = $this->upload->data();
$html .='File Uploaded !<br />';
}
if (!$this->upload->do_upload('pic2'))
{
$html .= $this->upload->display_errors();
$html .='<br />File Not Uploaded';
$upload_data2['file_name']='nopic.png';
}
else
{
$upload_data2 = $this->upload->data();
$html .='File Uploaded !<br />';
}
$dat=array(
'main_pic'=>$upload_data['file_name'],
'cover_pic'=>$upload_data2['file_name']
);
if($this->db->insert('picz', $dat))
return $html;
else
return 'Failed !';
}
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="pic1" />
<input type="file" name="pic2" />
<input type="submit" name="subpic" value="upload" />
</form>

Comments are closed.