Reputation: 5243
I use codeigniter and in upload file I have problem. file_name
is produced Repetitiously.
My Model: (db_category)
public function do_upload($route = "./category-pic/") {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $route,
'encrypt_name' => 'TRUE',
'max_size' => 3000
);
$this->load->library("upload", $config);
}
My Controller:
$this->db_category->do_upload("./product-pic/");
foreach ($_FILES as $key => $value) {
$this->upload->do_upload($key);
$data_name = $this->upload->data();
$k++;
if (is_uploaded_file($_FILES['file'.$k]['tmp_name'])) {
// This is produced Repetitiously sometimes for different pictures.
echo $data_name['file_name']. " ****** ";
}
}
My view is simple and static like :
echo '<input type="file" name="file1" id="my_uploader" style="width: 210px;" />' ;
echo '<input type="file" name="file2" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file3" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file4" id="my_uploader" style="width: 210px;" />';
NOTE: All pictures uploads fine with their own names, but the problem is in $data_name['file_name']
.
What is the problem? Thanks.
Upvotes: 0
Views: 108
Reputation: 5243
Finally I found the answer! It was a bad mistake from view part.
Input files was not written in order. For example it was like this:
echo '<input type="file" name="file5" id="my_uploader" style="width: 210px;" />' ;
echo '<input type="file" name="file2" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file3" id="my_uploader" style="width: 210px;" />';
I don't know why this can cause problem.
Upvotes: 0
Reputation: 1741
instead of
$data_name['file_name'];
use
$_FILES['file'.$k]['name'];
Upvotes: 1