在Codeigniter上传多个文件时出错 [英] Error when uploading multiple files in Codeigniter

查看:95
本文介绍了在Codeigniter上传多个文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在CodeIgniter中使用多个文件上传,但我收到一个错误:
您没有选择要上传的文件 p>

我的html代码:

 < input type =fileid =ModelImagename =ModelImage []multiple =multiplevalue =/> 

我的PHP代码:

  for($ i = 0; $ i< count($ _ FILES ['ModelImage'] [name]); $ i ++)
{
if ($ _FILES ['ModelImage'] ['name'] [$ i]))
{
$ config ['upload_path'] ='./uploads/starmodel/';
$ config ['allowed_types'] ='gif | jpg | png';
$ config ['file_name'] =star _。$ lastid。_。$ i.strrchr(basename($ _ FILES [ModelImage] [name] [$ i]),。 );
$ this-> upload-> initialize($ config);

if($ this-> upload-> do_upload('ModelImage'))
{
$ data = $ this-> upload-> data ;
$ udata = array('ModelImage'=> $ config ['file_name']);
$ this-> db-> where('ModelID',$ lastid);
$ this-> db-> update('starmodel',$ udata);
}
else
{
echo $ this-> upload-> display_errors();
}
}
}


解决方案>

name参数必须为 userfile



根据到CI文件上传文档


默认情况下,文件来自一个名为userfile的窗体
,并且窗体必须是一个multipart类型:




 < form method =postaction =some_actionenctype =multipart / form-data/> 
< input type =filename =userfilesize =20/>
< input type =submitvalue =upload/>
< / form>

据说,我不相信CI的库目前支持HTML5的文件上传。您应该围绕CI的论坛了解自定义库。


I am trying to use multiple file upload in CodeIgniter, but I'm getting an error: You did not select a file to upload.

My html code:

<input type="file" id="ModelImage" name="ModelImage[]" multiple="multiple"  value=""/>

My php code:

for($i = 0; $i < count($_FILES['ModelImage']["name"]); $i++)
{
  if (!empty($_FILES['ModelImage']['name'][$i]))
  {
    $config['upload_path'] = './uploads/starmodel/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['file_name']= "star_".$lastid."_".$i.strrchr(basename($_FILES["ModelImage"]["name"][$i]),".");
    $this->upload->initialize($config);

    if ($this->upload->do_upload('ModelImage'))
    {
      $data = $this->upload->data();
      $udata = array('ModelImage' => $config['file_name']);
      $this->db->where('ModelID', $lastid);
      $this->db->update('starmodel', $udata);
    }
    else
    {
      echo $this->upload->display_errors();
    }
  }
}

解决方案

The name parameter must be userfile

According to the CI File Uploading Documentation:

By default the upload routine expects the file to come from a form field called userfile, and the form must be a "multipart" type:

<form method="post" action="some_action" enctype="multipart/form-data" />
    <input type="file" name="userfile" size="20" />
    <input type="submit" value="upload" />
</form>

With that said, I do not believe CI's library currently supports HTML5's multiple file uploads. You should peak around CI's forums for custom libraries.

这篇关于在Codeigniter上传多个文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆