dongpan1416 2015-05-21 18:19
浏览 55


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;
        //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;


<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 class="span12" style="margin-top: 15px;">
                                    <output id="result" />

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)

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



  • ¥15 python使用pulp线性优化时报错
  • ¥15 开源或低价数据中台哪个最好
  • ¥15 arduino编程出现字符串疑似覆盖现象
  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?
  • ¥30 STK matlab python仿真
  • ¥15 关于IMageEnView 图标定位问题
  • ¥20 求解答(matlab)
  • ¥30 ffmpeg库使用过程中遇到的问题
  • ¥15 pyqt5 中python如何通过Qtwebchannel主动发消息给web前端
  • ¥15 关于HTML中title获取xml内容的问题