多次上传有时无法成功上传

时间:2019-02-08 03:26:57

标签: php codeigniter

我具有上载多个文件的功能,但有时文件未上载,但路径已成功添加到数据库。我不确定这是什么问题。我使用函数'times()'使它唯一,这是问题的根源吗?

我已经对其进行了测试,并且可以成功运行,但是在实施后,有时文件无法成功上传

if ($_FILES["lampiran"]["name"] != NULL) {

    $config = array();
    $ext = array();
    $records = array();

    $file_name = "Plan_".time();
    $files = $_FILES['lampiran'];
    $config['upload_path'] = "./uploads/Planning/attachment";
    $config['allowed_types'] = '*';

    foreach ($_FILES['lampiran']['name'] as $key => $value) {
        $ext[]= pathinfo($_FILES['lampiran']['name'][$key], PATHINFO_EXTENSION);
    }

    $cpt = count ($_FILES['lampiran']['tmp_name']);
        for($i=0; $i<$cpt; $i++){


        $_FILES['lampiran']['name']= $file_name.$i.'.'.$ext[$i];
        $_FILES['lampiran']['type']= $files['type'][$i];
        $_FILES['lampiran']['tmp_name']= $files['tmp_name'][$i];
        $_FILES['lampiran']['error']= $files['error'][$i];
        $_FILES['lampiran']['size']= $files['size'][$i];

        $records[] = $config['upload_path'].'/'.$_FILES['lampiran']['name'];

        $this->upload->initialize($config);
        if ( ! $this->upload->do_upload('lampiran'))
        {
            $error = array('error' => $this->upload->display_errors());
            print_r($error);

                        // $this->load->view('upload_form', $error);
        }

    }

    $pile = implode(";", $records);

    } else {
        $pile = NULL;
    }

1 个答案:

答案 0 :(得分:0)

在else条件下使用$ records也会使错误数组大于Like

if ( ! $this->upload->do_upload('lampiran'))
{
    $error[] = $this->upload->display_errors();
}else{
    $upload_data = $this->upload->data();
    $records[] = $config['upload_path'].'/'.$upload_data['file_name'];
}

在这里,您将获得$ error中的所有错误,并在记录中上传文件。