Welcome Guest, Not a member yet? Register   Sign In
uploading multiple images, issues with multiple thumbs
#1

[eluser]Unknown[/eluser]
Hello, I am new to Codeigniter and I am playing around with image upload and manipulation. I am attempting to upload multiple files and create a thumbnail for each one. The code below uploads multiple images just fine, but when using the upload->data() method to pull the full_path of the most recently uploaded file, it appears to grab only the first image uploaded. It is the same issue whether I set 'new_image' or 'create_thumb', it only creates a thumb for the first image uploaded.

Here is the code for the view:
Code:
<h1>New Entry</h1>

&lt;?php

$entry_types = array(
  '0' => '-Entry Type-',
  '1' => 'Normal Entry',
  '2' => 'Landmark Entry'
);

$js = 'onClick="cancel_modal()"';

echo form_open_multipart('entries/create_new_entry');
echo form_input('entry_name', 'Entry Title', 'id="entry_name" class="new_entry_field"');
//echo form_input('entry_author', 'Author', 'id="entry_author"');
echo form_textarea('entry_blurb', 'Entry Blurb', 'id="entry_blurb"');
echo form_dropdown('entry_type', $entry_types, '0');
echo form_upload('userfile1');
echo form_upload('userfile2');
echo form_upload('userfile3');
echo form_submit('submit', 'Create Entry');
echo form_button('cancel', 'Cancel', $js, 'id="entry_cancel"');
echo form_close();

?&gt;

Here is the code in the model:
Code:
&lt;?php

class Images_model extends CI_Model {

var $gallery_path;
var $gallery_path_url;

function __construct() {

  parent::__construct();
  
  $this->gallery_path = realpath(APPPATH.'../images/lifejournal/');
  $this->gallery_path_url = base_url().'images/lifejournal/';

}

function image_upload() {


for($i = 1; $i<=3; $i++) {
  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png',
   'upload_path'  => $this->gallery_path,
   'max_size'  => 2000
  );

  $this->load->library('upload', $config);
  $this->upload->do_upload('userfile'.$i);
  $image_data = $this->upload->data();
  
  
  $config = array(
   'source_image' => $image_data['full_path'],
   'new_image'  => $this->gallery_path.'/thumbs/',
   'maintain_ratio' => true,
   'width'   => 150,
   'height'  => 100
  );
  
  $this->load->library('image_lib', $config);
  $this->image_lib->resize();
  
  //$data = $this->image_lib->display_errors();
  //$this->write_error($data);

}

}

}

Any help would be truly appreciated.
#2

[eluser]codie[/eluser]
Hey eddykino,can u provide me full code for this.
Have u done this multi upload thing with only one image field????




Theme © iAndrew 2016 - Forum software by © MyBB