CodeIgniter文件上传更改循环内的文件名

The case is I have 3 file inputs. Each name attribute for them are file1, file2, and file3

Then inside my controller, I use switch case function for I want to rename the file.

file1 = 'label' file2 = 'meter' file3 = 'rumah'

for ($n=1; $n<=3; $n++) {
    if (empty($_FILES["file$n"]['name'])) continue;

    $filext = pathinfo($_FILES["file$n"]['name'],PATHINFO_EXTENSION);

    switch($n) {
        case 1: $namae = 'label'; break;
        case 2: $namae = 'meter'; break;
        case 3: $namae = 'rumah'; break;
    }

    $config['upload_path']      = $upload_path;
    $config['allowed_types']    = 'gif|jpg|png';
    $config['max_size']         = 1024 * 20;
    $config['file_name']        = $namae;

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

    if (!$this->upload->do_upload("file$n")) {
        ${"photo$n"."_upload"} = $this->upload->display_errors();
    } else {
        ${"photo$n"."_upload"} = $this->upload->data();
        $this->model->simpan_foto($id_survei,$namae,${"photo$n"."_upload"}['file_name']);
    }
}

But it didn't work! All 3 of the files are named with 'label', so it's label.png, label1.png, label2.png (because I not use $config['overwrite'])

How to accomplish this?

if there is only three file than try this code....

for ($n=1; $n<=3; $n++) {
    if (empty($_FILES["file$n"]['name'])) continue;

    $filext = pathinfo($_FILES["file$n"]['name'],PATHINFO_EXTENSION);

    if($n==1){
     $namae = 'label';
     }
     if($n==2){
     $namae = 'meter';
     }
     if($n==3){
     $namae = 'rumah';
    }

    $config['upload_path']      = $upload_path;
    $config['allowed_types']    = 'gif|jpg|png';
    $config['max_size']         = 1024 * 20;
    $config['file_name']        = $namae;

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

    if (!$this->upload->do_upload("file$n")) {
        ${"photo$n"."_upload"} = $this->upload->display_errors();
    } else {
        ${"photo$n"."_upload"} = $this->upload->data();
        $this->model->simpan_foto($id_survei,$namae,${"photo$n"."_upload"}['file_name']);
    }
}