I have been trying to upload multiple photos twice in a single form in codeigniter project,though the photos are uploading correctly but the name of photos are not been returned as per desired. for example if am uploading a photo named 'a.jpg' in first uploader and 'b.jpg' in second uploader,the names i am getting are "a.jpg,b.jpg" for first and "b.jpg,b(1).jpg" for second case. below is the code attached.
controller:-
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Imageupload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('imageupload_view', array('error' => ' ' ));
}
function doupload()
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
// echo $count;
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = 'application/views/uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000000';
//$config['max_width'] = '1024';
//$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
$names= implode(',', $name_array);
return $names;
}
function doupload_1()
{
$name_array = array();
$count = count($_FILES['file_1']['size']);
echo $count;
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['file_1']['name']=$value['name'][$s];
$_FILES['file_1']['type'] = $value['type'][$s];
$_FILES['file_1']['error'] = $value['error'][$s];
$_FILES['file_1']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['file_1']['size'] = $value['size'][$s];
$config['upload_path'] = 'application/views/uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000000';
//$config['max_width'] = '1024';
//$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
$names= implode(',', $name_array);
return $names;
}
public function check()
{
$data = $this->doupload();
$data_1 = $this->doupload_1();
print_r($data);
echo "<br>";
print_r($data_1);
}
}
?>
view:-
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo form_open_multipart('imageupload/check');?>
<input name="userfile[]" id="userfile" type="file" multiple="" />
<input name="file_1[]" id="file" type="file" multiple=""/>
<input type="submit" value="upload" />
<?php echo form_close() ?>
</body>
</html>
thanks in advance!