【问题标题】:Codeigniter file uploading errorCodeigniter 文件上传错误
【发布时间】:2016-10-22 12:51:47
【问题描述】:

我一直在尝试使用 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++;

【问题讨论】:

  • 也许这会起作用$config['upload_path'] = './assets/uploads/';
  • 我在父目录中有上传文件夹
  • 好吧,比从路径中删除点
  • 已经试过了。
  • 请找出上传错误。 $this->upload->display_errors()

标签: php codeigniter


【解决方案1】:

试试这个 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;
}

如果有任何疑问,请告诉我

【讨论】:

    【解决方案2】:

    您是否使用 html 表单操作来提交数据?

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-22
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多