Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Multiple Upload Codeigniter 3.0.4
- #VIEW----------------Upload_form.php------------------------------>
- <div>
- <b>Multiple Upload form</b><br/>
- <?=form_open_multipart('upload/simpan');?>
- <?php for ($i = 1; $i <=3; $i++): ?>
- <div class="form_element">
- <label for="photo<?=$i?>">File <?=$i?></label>
- <?=form_upload(array('name' => 'userfile'.$i))?>
- </div>
- <?php endfor ?>
- <input type="submit" value="Upload" name="kirim"/>
- <?=form_close();?>
- </div>
- #CONTOLLERS-----------------Upload.php------------------------>
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Upload extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- $this->load->helper(array('form', 'url','html'));
- $this->load->model('Upload_model');
- }
- function index()
- {
- $this->load->view('upload_form');
- }
- public function simpan()
- {
- if($this->input->post('kirim')) {
- $config['upload_path'] = 'uploads/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '3000';
- $this->load->library('upload', $config);
- $result_array = array();
- for ($i = 1; $i <=3; $i++){
- if (!$this->upload->do_upload('userfile'.$i)){
- $sub_data['error'] = $this->upload->display_errors();
- }else{
- array_push($result_array,$this->upload->data());
- }
- }
- $sub_data = array(
- 'file' => $result_array[0]['file_name'],
- 'file2' => $result_array[1]['file_name'],
- 'file3' => $result_array[2]['file_name'],
- );
- }
- $this->Upload_model->create($sub_data);
- redirect(site_url('upload'));
- }
- }
- #MODEL-------------------Upload_model.php------------------------->
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Upload_model extends CI_Model {
- public function create($sub_data)
- {
- $this->db->insert('images', $sub_data);
- }
- }
- #DATABASE----------------------------------------------------->
- CREATE TABLE IF NOT EXISTS `images` (
- `id` int(10) NOT NULL,
- `file` text NOT NULL,
- `file2` text NOT NULL,
- `file3` text NOT NULL
- ) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=latin1;
Advertisement
Add Comment
Please, Sign In to add comment