0

CONTROLLER

$config['upload_path'] = '../ci/assets/images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024'; 
$config['max_height'] = '768';

//load upload library
$this->load->library('upload', $config);

//load mPhoto model
$this->load->model("carstock_model"); 

//Check to see if upload was activated if/then/else statement
if (! $this->upload->do_upload())
{
    $error = array('error' => $this->upload->display_errors()); 
    $this->load->view('admin_view.php', $error);
} 
else 
{
    for($i=1; $i<6; $i++) {
        $data = array('upload_data' => $this->upload->data()); 
        $data2 = $this->input->post(NULL, TRUE); //returns POST items with XSS filter
        $filename = $data['upload_data']['file_name']; //obtain the upload filename
        $data2['picture' .$i]= $filename .$i; //get and set the filename

        // $data2['PhotoFilenameLarge']=$filename; //get and set the filename
        $this->carstock_model->insertData($data2); //add the db
    }

    $this->load->view('upload_success', $data); //display the success view
}

VIEW

...    
<input name="userfile" type="file" multiple="multiple" />
...

MODEL

public function insertData($data){
$this->db->insert("carstock", $data); //active record
}

The problem is when passing the files in mysql takes just the last selected image as input and stores the name wrong. Thanks for your help.

1 Answer 1

1
for($i = 0;$i<=2;$i++){
    $name = 'image_0'.$i;

    if(isset($_FILES[$name])){
        $this->upload->do_upload($name);
        $data = $this->upload->data();
        dump($data['file_name']);
    }else{
        // do nothing
} // end of for loop

dump($data['file_name']); will dump file name. But you must select file for every field

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.