PHP 代码点火器,错误:重命名上传文件时数组到字符串的转换



当我尝试重命名图像文件时,我在Codeigniter中上传文件时遇到错误。在本地服务器中工作正常,但在实时服务器上传成功时,但它显示错误:数组到字符串的转换未定义的索引:指向此行的用户文件:

$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();
}
}

我哪里做错了?

问题在于将变量$upload更改为$upload_data

在此之前,检查文件是否发布以检查未定义的索引

public function uploadImages(){
print_r($_FILES);exit; /*Comment after checked  */
$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();
}
}

相关内容

  • 没有找到相关文章