dongpan1416 2015-05-21 18:19
浏览 55
已采纳

如何在codeigniter中添加多个文件

I am using codeigniter in my project, i am facing one problem while uploading multiple files to database. uploaded images was not moving to the particular folder. so my file was not saving in my database. i have attach my code below please find the below attachment and tell me what i am missing. Thanks in advance. Model:

public function myfunction(){
$config = array(
            'upload_path' => 'charity_gallery',
            'max_size' => 2000 * 2000,
            'allowed_types' => 'gif|jpeg|jpg|png',
            'overwrite' => true,
            'remove_spaces' => true);
    $images = array();
    $this->load->library('upload', $config);

    $files = $_FILES;
    $count = count($_FILES['charity_image']['name']);
    echo $count;

    for ($i = 0; $i < $count; $i++) {

        $_FILES['charity_image']['name'] = $files['charity_image']['name'][$i];
        $_FILES['charity_image']['type'] = $files['charity_image']['type'][$i];
        $_FILES['charity_image']['tmp_name'] = $files['charity_image']['tmp_name'][$i];
        $_FILES['charity_image']['error'] = $files['charity_image']['error'][$i];
        $_FILES['charity_image']['size'] = $files['charity_image']['size'][$i];

        $fileName = $_FILES['charity_image']['name'];
        $images[] = $fileName;
        $config['file_name'] = $fileName;
        $imgName = 'charity_gallery/'.$fileName;
        //echo $imgName;
        $this->upload->initialize($config);
        //echo "hello"."INSERT INTO `charity_gallery` (charity_id, image_name, created_on) VALUES ('$cid', '$imgName', '$createdOn')";
        if ($this->upload->do_upload('charity_image')) {
            echo "how"."INSERT INTO `charity_gallery` (charity_id, image_name, created_on) VALUES ('$cid', '$imgName', '$createdOn')";
            $query = $this->db->query("INSERT INTO `charity_gallery` (charity_id, image_name, created_on) VALUES ('$cid', '$imgName', '$createdOn')");

        } 


    }
    $aff = $this->db->affected_rows();
    return $aff;
}

Html:

<div class="control-group" style="padding:15px;">
                                <label class="control-label" for="basicinput" style="padding:10px;">Image Gallery:</label>
                            <div class="controls">
                                <div class="input-append span6">
                                    <input type="file" class="span12" placeholder="Upload file" id="charity_image" name="charity_image[]" multiple>
                                </div>
                                <div class="span12" style="margin-top: 15px;">
                                    <output id="result" />
                                </div>
                            </div>
                            </div>

In this, If i add totally 3 images means only one image getting added and uploaded. remaining two image was not getting upload. I dont know where i am doing wrong.

  • 写回答

1条回答 默认 最新

  • doubu4826 2015-05-21 18:35
    关注

    Is your path correct?

    'upload_path' => 'charity_gallery',

    Where is located this folder? Try ./charity_gallery/ instead. (make sure to have the correct permissions too)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算