Welcome Guest, Not a member yet? Register   Sign In
Problem with new Upload class in 1.7.2
#1

[eluser]copernicus[/eluser]
I upgraded my CI from 1.7.1 and I think something broke in the Upload class. I am getting this error when I submit:
Code:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: libraries/Upload.php
Line Number: 154

Line 154 is:
Code:
if ( ! is_uploaded_file($_FILES[$field]['tmp_name']))

I think it is due to how I am naming the input field for the uploading? I am doing a multiple file upload so the input field looks like:
Code:
<input type="file" name="userfile[]" size="20" class="multi" />

So I'm guessing it doesn't like the
Code:
name="userfile[]"

Anybody have any ideas on how to get around this?
#2

[eluser]umefarooq[/eluser]
hi you are sending array of urserfile field for that you have to loop till the last element of array

Code:
for first element

if ( ! is_uploaded_file($_FILES[$field]['tmp_name'][0]))

here is some code for uploading multiple file also single file upload

Code:
if(isset ($_FILES[$field]) and is_array($_FILES[$field]['error']) ){
            $count = count($_FILES[$field]['error']);
            for ($i = 0; $i < $count; $i++)
            {
                $data = null;
                // Give it a name not likely to already exist!
                $pseudo_field_name = '_psuedo_'. $field .'_'. $i;
                // Mimick the file
                $_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]
                );
                // Let do_upload work it's magic on our pseudo file field
                $this->ci->upload->do_upload($pseudo_field_name);
                $data = $this->ci->upload->data();

                $success[$i] = $data['file_name'];

            }
        }else{
            
            if(!$this->ci->upload->do_upload($field)){
                $success = array('error' => $this->ci->upload->display_errors());
            }
            else{
                $data = $this->ci->upload->data();
                $success = $data['file_name'];
            }
        }




Theme © iAndrew 2016 - Forum software by © MyBB