Codeigniter文件上传错误

时间:2016-10-22 12:51:48

标签: php codeigniter

我一直在尝试使用codeigniter文件上传库上传多个图片。一切正常,除非它没有将图像保存在目录中, 我有检查权限一切都很完美。我也尝试过改变套餐,但仍面临同样的问题。

这是我的上传代码。

   $count = count($_FILES['upload_' . $increment]['size']);

   for ($s = 0; $s <= $count-1; $s++) {
     $config['upload_path']   = './uploads/';
     $config['allowed_types'] = 'gif|jpg|png|jpeg';
     $config['max_size']      = '10000';
     $config['max_width']     = '2048';
     $config['max_height']    = '1152';

     $image = $config['file_name'] = $c_id . '-' . $s . '.jpg';

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

     $data = $this->upload->data();
     $data = array('c_id' => $c_id, 'image'=> $image);

     $this->db->insert('images', $data);
   }

   $increment++;

2 个答案:

答案 0 :(得分:0)

您使用html表单操作提交数据吗?

如果是,请将enctype="multipart/form-data"添加到您的表单标记中:

<form action="your action url" method="post" enctype="multipart/form-data">

答案 1 :(得分:0)

试试这个 Downlaod this Codeigniter Library and put this file under application/libraries

控制器

if ($_FILES) {
    $config['upload_path']   = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '200';
    $config['max_width']     = '1024';
    $config['max_height']    = '768';
    $this->load->library('upload');
    $this->upload->initialize($config);
    if (!$this->upload->do_multi_upload("file")) {
        $data['errors'] = ($this->upload->display_errors());
    } else {
        $images = ($this->upload->get_multi_upload_data());
        for ($i = 0; $i < count($images); $i++) {
        $this->user_model->addUserImage($images[$i]);
        }
    }

模型

public function addUserImage($image)
{
  $image_data=array(
    'name'=>$image['file_name']
  );
   $this->db->insert('user_images',$image_data);
   return true;
}

如果有任何查询,请告诉我