<
>

Codeigniter实现多文件上传并创建多个缩略图

2019-04-16 05:32:28 来源:易采站长站 作者:于丽


          $this->image_lib->initialize($configThumb);
          $this->image_lib->resize();
          //初始化600*600
          $configLarge['source_image'] = $data['full_path']; //文件路径带文件名
          $this->image_lib->initialize($configLarge);
          $this->image_lib->resize();
        }

        //插入图片信息到album表,插入的文件名为source目录文件名
        $picture = array(
            'filename' => $data['file_name'],
            'albumID' => $this->uri->segment(4,0),
            'uid' => $this->session->userdata('uid'),
            'dateline' => time(),
            'describe' => '',
            'click' => 0
        );

        $this->load->model('album_model');
        $this->album_model->AddPic($picture);
        $picture = array();
      }
    }

    /* 转出 */
    $albumID = $this->uri->segment(4);
    $backurl = site_url() . 'photo/editpic/album/' .$albumID;
    $this->session->set_flashdata('msg','图片上传成功.');
    redirect($backurl,'refresh');
  }
}

views:new_pic.view文件:

<form method="post" action="<?php echo site_url() ?>photo/upload/go/<?php echo $albumID ?>" enctype="multipart/form-data">
  <input type="file" name="image1" class="files"/><br />
  <input type="file" name="image2" class="files"/><br />
  <input type="file" name="image3" class="files"/><br />
  <input type="file" name="image4" class="files"/><br />
  <input type="file" name="image5" class="files"/><br />
  <br />
  <p><input type="submit" name="go" value="上传照片" class="button" /></p>
</form>

此外需要注意:

1.要一次上传几个文件,修改表单和控制器中循环部分的参数就好。
2.albumsource 是上传后原图目录  large和thumb分别是两次执行$this->image_lib->resize();后存放缩略图的目录

暂时禁止评论

微信扫一扫

易采站长站微信账号