2011-10-18 14:19
浏览 59


im having a page that will insert username, ID and the user must be able to upload upto 10 images .

The main problem that im having is when it comes to uploading multiple images using codeigniter.

  1. can someone suggest me how can i pass each image path of each individual image to the array so i can pass it to the database.

  2. and if the user selects to upload less than 10 images, like 2 or 5 then how can i ignore the error that says a file hasn't been selected and jst pass only the images that has been uploaded.

    <form method="post" action="uploader/go" enctype="multipart/form-data">
    <input name="username" type="text" /><br />
    <input name="nid" type="text" /><br />
    <input type="file" name="image1" /><br />
    <input type="file" name="image2" /><br />
    <input type="file" name="image3" /><br />
    <input type="file" name="image4" /><br />
    <input type="file" name="image5" /><br />
    <input type="file" name="image6" /><br />
    <input type="file" name="image7" /><br />
    <input type="file" name="image8" /><br />
    <input type="file" name="image9" /><br />
    <input type="file" name="image10" /><br />
    <input type="submit" name="go" value="Upload!!!" />

sample controller

$image_data=array('image_info' => $this->upload->data('image')); 

$data =array(

any help will be appreciated.

图片转代码服务由CSDN问答提供 功能建议



  1. 有人可以建议我如何将每个 单个图像的每个图像路径传递给数组,以便将其传递给数据库。

  2. 并且如果用户选择上传少于10个图像,例如2或5,那么如何忽略文件未被选择的错误并且jst通过 只有已上传的图片。

     &lt; form method =“post”action =“uploader / go”enctype =“multipart / form-data”&gt; 
    &lt  ;输入名称=“用户名”类型=“文字”/&gt;&lt; br /&gt; 
    &lt;输入名称=“nid”type =“text”/&gt;&lt; br /&gt; 
    &lt;输入类型=  “file”name =“image1”/&gt;&lt; br /&gt; 
    &lt; input type =“file”name =“image2”/&gt;&lt; br /&gt; 
    &lt; input type =“file”name  =“image3”/&gt;&lt; br /&gt; 
    &lt; input type =“file”name =“image4”/&gt;&lt; br /&gt; 
    &lt; input type =“file”name =“image5”  /&gt;&lt; br /&gt; 
    &lt; input type =“file”name =“image6”/&gt;&lt; br /&gt; 
    &lt; input type =“file”name =“image7”/&gt;&lt;  ; br /&gt; 
    &lt; input type =“file”name =“image8”/&gt;&lt; br /&gt;  ; 
    &lt; input type =“file”name =“image9”/&gt;&lt; br /&gt; 
    &lt; input type =“file”name =“image10”/&gt;&lt; br /&gt; 
    &lt;  input type =“submit”name =“go”value =“上传!!!”  /&gt; 
    &lt; / form&gt; 


     <  code> $ image_data = array('image_info'=&gt; $ this-&gt; upload-&gt; data('image'));  
     $ image_path = $ image_data ['image_info'] ['full_path']; 
     $ data = array(
    'id'=&gt; uniqid('id _'),
    'nID'=&gt;  $ this-&gt; input-&gt; post('nid'),
    'username'=&gt; $ username,
    'image1'=&gt; $ image_path 


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyang5716 2011-10-18 14:29

    change the input names to:

    <input type="file" name="image[1]" /><br />
    <input type="file" name="image[2]" /><br />
    <input type="file" name="image[3]" /><br />

    instead and $this->upload->data('image') will be an array.

    And then you can do:

    foreach($this->upload->data('image') as $image) {
       passItToTheDatabase(); // your custom function
    打赏 评论

相关推荐 更多相似问题