开发者

Problem with multiple uploading image

开发者 https://www.devze.com 2023-04-05 16:42 出处:网络
I use codeigniter. I want multiple upload image, for this work, i use library Multi_upload and jquery.MultiFil开发者_如何学Ce.

I use codeigniter. I want multiple upload image, for this work, i use library Multi_upload and jquery.MultiFil开发者_如何学Ce.

i have in output, this Array ( [0] => [1] => [2] => ) no => this is is from line 18 (print_r($error);echo 'no';) in the my code, and inserted to databse table this: [](i want insert file name) . how can fix it?

My Html: http://pastebin.com/8YWJS2hy

library Multi_upload: http://pastebin.com/115ASstV

jquery.MultiFile: http://pastebin.com/0cyU8HvA

My Controller:

function insert_data(){
    $config['upload_path']   = './uploads/'; // server directory
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '512';

    $this->load->library('Multi_upload');
    $error = array();
    $data  = array();
    for ($i = 0; $i < count($_FILES['userfile']['name']); $i++) {
        $this->upload->initialize($config);
        if (!$this->multi_upload->go_upload('userfile', $i)) {
            $error[] = $this->upload->display_errors();
        }
        $data[$i] = $this->multi_upload->go_upload();
        //gradually build up upload->data()
    }

    if (count($error) > 0) {
        print_r($error); //Line 18
        echo 'no';
    } else {
        print_r($data);
        echo 'ok';
    }

    $data = array(
        //'name' => $this -> input -> post('name'),
        //'term' => $this -> input -> post('term'),
        'image' => json_encode($data)
    );

    $this->db->insert('table', $data);
}


You should count $_FILES['userfile'] , not the name inside.

Also make sure that at the HTML page sending the request , all file fields are called userfile[] (e.g. )

0

精彩评论

暂无评论...
验证码 换一张
取 消