CodeIgniter Forums
[Solved] Curious: $this->upload->display_errors(); - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: [Solved] Curious: $this->upload->display_errors(); (/thread-61252.html)



[Solved] Curious: $this->upload->display_errors(); - vrsotto - 04-04-2015

Hi

I'm able to do multiple uploads using the following codes (bellow). on $config (req. var in $this->process_file_upload($field_file_name$config)), i set allowed file types to "jpg|gif|png". So, when i test and upload files like in "file.htm, file.txt and then file.jpg". basically, files with ".htm" and ".txt" will not be uploaded. arrays $data[0]['error'] and arrays $data[2]['error'] should each have value "The filetype you are attempting to upload is not allowed." but what is happining is that arrays $data[2]['error'] kind'a concatenate value from $data[0]['error'], is this normal?  

Please see my attached file showing my dump result.

PHP Code:
for ($count 0$count $number_of_files$count++) { 
$this->load->library('upload'$config);

$_FILES[$field_file_name]['name'    $files['name'][$count];
$_FILES[$field_file_name]['type'    $files['type'][$count];
$_FILES[$field_file_name]['tmp_name'] = $files['tmp_name'][$count];
$_FILES[$field_file_name]['error'   $files['error'][$count];
$_FILES[$field_file_name]['size'    $files['size'][$count];

$data[] = $this->process_file_upload($field_file_name$config);
}

dump($data); // dump() is same as print_r(), a custom function

public function process_file_upload($field_file_name$config = array()) {
// Process Upload(s)
if ($this->upload->do_upload($field_file_name)) {
 
$data['upload'] = $this->upload->data();
} else {
 
$data['error'] = $this->upload->display_errors();
}
return 
$data;


Thanks,

vrsotto


RE: Curious: $this->upload->display_errors(); - gadelat - 04-04-2015

Yes. display_errors() outputs uploading errors for all of the files, doesn't matter if files were uploaded one by one. Remove this from loop
(04-04-2015, 10:11 AM)vrsotto Wrote:
PHP Code:
} else {
 
$data['error'] = $this->upload->display_errors();

and use that function after the loop


RE: [Solved] Curious: $this->upload->display_errors(); - vrsotto - 04-04-2015

Ah, Yes. Got the point! Thanks!

(04-04-2015, 11:44 AM)gadelat Wrote: Yes. display_errors() outputs uploading errors for all of the files, doesn't matter if files were uploaded one by one. Remove this from loop


(04-04-2015, 10:11 AM)vrsotto Wrote:
PHP Code:
} else {
 
$data['error'] = $this->upload->display_errors();

and use that function after the loop