Multiple File Upload - El Forum - 02-01-2011
[eluser]sahanlak[/eluser]
Hello,
I'm using CI 1.7.3
I have a form with 2 upload fields, name="share_image" and name="splash_image"
I have a model with a upload method
Code: function upload_image($original_name, $field){
$ext = end(explode(".", $original_name));
$config['upload_path'] = realpath(APPPATH.'../static/uploads');
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
//$config['max_width'] = '520';
//$config['max_height'] = '650';
$config['overwrite'] = TRUE;
$config['file_name'] = $original_name;
$this->load->library('upload', $config);
unset($config);
if($this->upload->do_upload($field)){
return $this->upload->data();
}
else {
return false;
}
}
In the method, I pass $_FILES['share_image']['name'] and $_FILES['splash_image']['name'] for the $original_name, and upload field's name for the $field, in this case 'share_image' and 'splash_image'.
So in my controller,
Code: if(isset($_FILES['splash_image']) && $_FILES['splash_image']['error']!=4) {
$data=$this->page_model->upload_image($_FILES['splash_image']['name'], 'splash_image');
print_r($data);
}
if(isset($_FILES['share_image']) && $_FILES['share_image']['error']!=4) {
$data=$this->page_model->upload_image($_FILES['share_image']['name'], 'share_image');
print_r($data);
}
After uploading 2 files using the form, array gave me this
Code: Array
(
[file_name] => 1294320008_Downloads.png
[file_type] => image/png
[file_path] => /home4/viralage/public_html/ssr/static/uploads/
[full_path] => /home4/viralage/public_html/ssr/static/uploads/1294320008_Downloads.png
[raw_name] => 1294320008_Downloads
[orig_name] => 1294320008_Downloads.png
[client_name] => 1294320008_Downloads.png
[file_ext] => .png
[file_size] => 16.78
[is_image] => 1
[image_width] => 128
[image_height] => 128
[image_type] => png
[image_size_str] => width="128" height="128"
)
Array
(
[file_name] => 1294320008_Downloads.png
[file_type] => image/png
[file_path] => /home4/viralage/public_html/ssr/static/uploads/
[full_path] => /home4/viralage/public_html/ssr/static/uploads/1294320008_Downloads.png
[raw_name] => 1294320008_Downloads
[orig_name] => 1294320008_Downloads.png
[client_name] => 1292927463_iconthemes.png
[file_ext] => .png
[file_size] => 20.31
[is_image] => 1
[image_width] => 128
[image_height] => 128
[image_type] => png
[image_size_str] => width="128" height="128"
)
Why does [orig_name] becomes the same in both arrays ?
Multiple File Upload - El Forum - 02-01-2011
[eluser]sahanlak[/eluser]
Found the solution, $this->upload->initialize($config);
|