[eluser]Latavish[/eluser]
Hi Guys,
I have read and re-read thru the forum about this issue but i can't seem to locate an answer anywhere. I'll try my best to break this down and explain exactly what im trying to do. So I hope you CI gurus can understand me. :-)
From you guys here at the CI forums I have figured out how to upload multiple files via CI and that seems to work fine. The files are uploaded to my /uploads/ directory which is just a temp directory till i get the files processed, meaning resized and moved to the users storage folder.
Now here is my problem that I just can't seem to figure out. When I upload more then 1 file at a time, it only processes the 1st FILE and not the other files. Dont get me wrong, all files are uploading but when its not looping thru the (i'm assuming) the $_files array to process not just the 1st, but all files. You'll notice the "$this->Process_image->process();" which does the processing. All this is suppose to do is to move the uploaded files from the uploads folder to the users actually storage folder and adds a random code to the org file to prevent the same file name can't be uploaded and overwritten. Like i stated everything works perfect for the 1st uploaded file but any other files are not being processed.
Now I had the understanding that this would loop thru the files array and process each files just as it loops thru and uploads each file. But i guess thats just not the case.
Here is the Upload Controller
Code:
function picupload()
{
//Load Model
$this->load->model('Process_image');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048'; //2 meg
$this->load->library('upload');
$keys = array_keys($_FILES);
$errors = array();
$uploads = array();
//foreach($_FILES as $key => $value)
for( $i=0; $i<8; $i++ ){
$this->upload->initialize($config);
$field_name = "imagefile".$i;
if(!empty($$field_name['temp_name']))
{
if ( ! $this->upload->do_upload($field_name))
{
$errors[] = $this->upload->display_errors();
}
else
{
//$uploads[] = $this->upload->data();
$this->Process_image->process();
}
}
}
}
And Here is the Model
Code:
function process()
{
//Get File Data Info
$uploads = $this->upload->data();
//Generate code
$code = generate_code(7);
//Move File to User Folder Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $uploads['full_path'];
//$config['create_thumb'] = TRUE;
//$config['master_dim'] = 'height';
//$config['quality'] = 100;
$config['new_image'] = $this->config->item('userfiles').$this->session->userdata('username').'/pictures/'.$code.$uploads['orig_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
And the view file!
Code:
<table width="900" border="0" cellspacing="1" cellpadding="1">
<tr>
<td valign="top"><div align="center">
<p class="contentheading">Picture/Image Upload</p>
<table width="550" border="0" cellspacing="1" cellpadding="3">
<tr>
<td><div align="center"><?php echo form_open_multipart('upload/picupload'); ?>
<p>1.
<input type="file" name="imagefile1" id="imagefile1" />
</p>
<p>2.
<input type="file" name="imagefile2" id="imagefile2" />
</p>
<p>3.
<input type="file" name="imagefile3" id="imagefile3" />
</p>
<p>4.
<input type="file" name="imagefile4" id="imagefile4" />
</p>
<p>5.
<input type="file" name="imagefile5" id="imagefile5" />
</p>
<p>6.
<input type="file" name="imagefile6" id="imagefile6" />
</p>
<p>7.
<input type="file" name="imagefile7" id="imagefile7" />
</p>
<p>8.
<input type="file" name="imagefile8" id="imagefile8" />
<br />
<br />
<span class="category">Note: 2MB Per File Size Limit! Any Files Over 2MB Will Not Be Uploaded!</span></p>
<p><?php echo form_submit('mysubmit', 'Upload Pics!'); ?><?php echo form_close(); ?></p>
</div></td>
</tr>
</table>
<p class="stickynote">Image File Size May NOT Exceed 2 mega bites<br />
Only JPG, JPEG, GIF, PNG Accpeted</p>
</div> <div align="center"></div></td>
</tr>
</table>
And right now the model is just a BETA version and I hope to work on it a little more to also create a thumb and move the org file to the users storage folder. But I need to fix this main problem 1st.
Can someone please help me out!! Been working on this for 3 days now and i'm totally stuck. Thanks a million in advance guys!!!
Latavish