PHP Codeigniter,错误:重命名上载文件时数组到字符串的转换

问题描述 投票:0回答:1

当尝试重命名图像文件时,在本地代码服务器上工作正常,但是在实时服务器上成功上传,但是显示错误:数组到字符串转换未定义索引:用户文件指向此行:模型文件上的$image_name = "image-slider" . date("Y-m-d-h-i-sa").$_FILES["userfiles"]['name'];

我的控制者:

    public function uploadImages()
{
    $result = $this->M_images->uploadImages();

    if($result){
    $this->session->set_flashdata('upload_success_msg', 'Upload Success!');
    }
    else
    {
    $this->session->set_flashdata('upload_error_msg', 'Upload Error!');
    }

    redirect(base_url('backend/homepage/C_images'));
}

这是我的模特:

    public function uploadImages()
{
    $image_name = "image-slider" . date("Y-m-d-h-i-sa").$_FILES["userfiles"]['name'];

    $upload = array(

        'slider_title' => $this->input->post("slider-title"),
        'slider_alt' => $this->input->post("slider-alt"),
        'slider_link' => $this->input->post("slider-url"),
        'slider_desc' => $this->input->post("slider-description")
    );

        $config['upload_path'] = "./assets/uploads/sliders";
        $config['allowed_types'] = 'gif|jpeg|jpg|png';
        $config['overwrite'] = TRUE;
        $config['file_name'] = $image_name;

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

    if ( ! $this->upload->do_upload('slider-file'))
    {
        $this->db->insert($this->tableslider, $upload);
        return $this->db->insert_id();
    }
    else
    {
        $data = $this->upload->data();
        $upload['slider_file'] = $data['file_name'];
        $this->db->insert($this->tableslider, $upload);
        return $this->db->insert_id();
    }
}

我在哪里做错了?之前感谢

php codeigniter codeigniter-3
1个回答
0
投票

问题出在变量中,将$ upload更改为$ upload_data

 public function uploadImages(){
 $image_name = "image-slider" . date("Y-m-d-h-i-sa").$_FILES["userfiles"]['name'];
 $upload_data = array(
    'slider_title' => $this->input->post("slider-title"),
    'slider_alt' => $this->input->post("slider-alt"),
    'slider_link' => $this->input->post("slider-url"),
    'slider_desc' => $this->input->post("slider-description")
);

    $config['upload_path'] = "./assets/uploads/sliders";
    $config['allowed_types'] = 'gif|jpeg|jpg|png';
    $config['overwrite'] = TRUE;
    $config['file_name'] = $image_name;

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

 if ( ! $this->upload->do_upload('slider-file')){
    $this->db->insert($this->tableslider, $upload_data);
    return $this->db->insert_id();
}else{
    $data = $this->upload->data();
    $upload_data['slider_file'] = $data['file_name'];
    $this->db->insert($this->tableslider, $upload_data);
    return $this->db->insert_id();
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.