Welcome Guest, Not a member yet? Register   Sign In
Uploading multiple files/images
#1

Good day.

I need to display the images i have uploaded to my db with the following code.

"    function create_asset(){
        $data = array(
            'formTitle' => 'Create Asset',
            'title' => 'Create Asset',
        );


        $this->load->library('form_validation');

        $this->form_validation->set_rules('asset_name', 'Asset Name', 'trim|required|callback_select_validate');
        $this->form_validation->set_rules('asset_description', 'Asset Description', 'trim|required|callback_category_validate');
        $this->form_validation->set_rules('serial_number', 'Serial Number', 'required|callback_asset_exists');

        $postData = $this->input->post();


        if($this->form_validation->run() === FALSE)
        {
                $data['supplier'] = $this->admin_model->get_supplier();
                $data['asset_category'] = $this->admin_model->get_asset_category();
                $data['location'] = $this->admin_model->get_location();
                $data['room'] = $this->admin_model->get_room();
                $data['status'] = $this->admin_model->get_status();
                $this->load->view('frame/header_view');
                $this->load->view('frame/sidebar_nav_view');
                $this->load->view('asset/create_asset', $data);

        } 

        else

        {


        $name_array = array();
        $count = count($_FILES['userfile']['size']);
        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'] = './uploads/asset';
            $config['allowed_types'] = 'gif|jpg|png';
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $data = $this->upload->data();
        $name_array[] = $data['file_name'];
            }
            $names= implode(',', $name_array);
            
            //Prepare array of user data
            $userData = array(
                    'name' => $this->input->post('asset_name'),
                    'item_description' => $this->input->post('asset_description'),
                    'brand' => $this->input->post('brand'),
                    'serial_number' => $this->input->post('serial_number'),
                    'model' => $this->input->post('asset_model'),
                    'supplier' => $this->input->post('supplier'),
                    'category' => $this->input->post('asset_category'),
                    'location' => $this->input->post('location'),
                    'room' => $this->input->post('room'),
                    'date_pruchase' => $this->input->post('date_purchase'),
                    'purchase_price' => $this->input->post('purchase_price'),
                    'ip' => $this->input->post('ip'),
                    'mac' => $this->input->post('mac'),
                    'status' => $this->input->post('status'),
                    'files' => $names
      
                );

            //Pass user data to model
            $insertUserData = $this->admin_model->inset_asset($userData);
            
            //Storing insertion status message.
            if($insertUserData){
                redirect('admin/create_asset');
                $this->session->set_flashdata('success_msg', 'User data have been added successfully.');

            }else{
                $this->session->set_flashdata('error_msg', 'Some problems occured, please try again.');
            }
            }

        }"

Model_view

" function get_assets($limit, $start, $id=0)
    {
        if(empty($id)){
            $this->db->limit($limit, $start);
            $query = $this->db->get('tbl_asset_register');
            if ($query->num_rows() > 0) {
                foreach ($query->result() as $row) {
                    $data[] = $row;
                }
                return $data;
            }
            return false;
        } else {
            $query = $this->db->get_where('tbl_asset_register', array('id' => $id));
            return $query->row_array();
        }

    }"

I am trying to dipslay the images in a table for the specific id selected and display all the images in a table.
The code i've used in my view so far that display all the images uploaded in the db.

"<?php foreach($data  as $file): ?>

                                <center><img class="thumbnail" style="height: 300px; width: 300px;" src="<?php echo base_url('uploads/asset/' . $data['files']);?>"></center>

                            <?php endforeach; ?>"
Reply
#2

Please use code tags when displaying code [ code] your code [ /code]

remove the spaces in the code tags.

For what you want you would be better off using Bootstrap 4 it has columns
that will line up to do what you want along with responsive images.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB