[eluser]eokorie[/eluser]
I am currently using the code below in an attempt to upload multiple files.
Code:
function do_upload()
{
$this->folder = './uploads/';
$this->dynamicFolder = get_realpath(APPPATH.$this->folder);
$config['upload_path'] = $this->dynamicFolder;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
// $this->load->library('upload', $config);
$this->upload->initialize($config);
$field = 'userfile';
if(isset ($_FILES[$field]) and is_array($_FILES[$field]['error']) )
{
$count = count($_FILES[$field]['error']);
for ($i = 0; $i < $count; $i++)
{
$data = null;
$pseudo_field_name = '_psuedo_'. $field .'_'. $i;
$_FILES[$pseudo_field_name] = array(
'name' => $_FILES[$field]['name'][$i],
'size' => $_FILES[$field]['size'][$i],
'type' => $_FILES[$field]['type'][$i],
'tmp_name' => $_FILES[$field]['tmp_name'][$i],
'error' => $_FILES[$field]['error'][$i]
);
$this->upload->do_upload($pseudo_field_name);
$data = $this->upload->data();
$success[$i] = $data['file_name'];
$this->_createThumbnail_small($data['file_name']);
$data['uploadInfo'] = $data;
$data['thumbnail_small'] = $data['raw_name'] . '_small' . $data['file_ext'];
$this->session->set_flashdata('notice',$success[$i]);
$this->load->view('my_upload_success',$data);
}
}else{
if(!$this->upload->do_upload($field))
{
//$success = array('error' => $this->upload->display_errors());
//$this->session->set_flashdata('notice',$success);
// $this->load->view('my_upload');
//redirect(base_url().'my_upload','location');
echo $this->upload->display_errors();
}
else {
$data = $this->upload->data();
$success = $data['file_name'];
//$this->session->set_flashdata('notice',$success);
//redirect(base_url().'my_upload_success','location');
}
}
}
I opted to use the JQuery Multifile plugin as Uploadify just was too much work. SO far things are going well but I am hitting a couple of snags. If I upload just one file, things go well. When I try to upload say 3 files for example, the first file that is uploaded retains its filename, but the last two don't. i.e. first file upload keeps it name of say desert.jpg. But the second file called tulips.jpg gets renamed to desert.jpg.jpg and the 3rd file gets renamed to desert.jpg.jpg.jpg.
Anyone have a solution to this problem? Thanks