EllisLab text mark
Advanced Search
1 of 3
1
   
Multiple file upload library
Posted: 28 March 2012 11:35 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
Nihilistik - 28 March 2012 01:31 PM

Hi there!

Let me know if there is any kind of issue or style violation.

Hi, Nihilistik!

You have this in your view file

<form method="POST" action="" enctype="multipart/form-data">
    <
input type="files[]" name="file_1" size="20" multiple="multiple"/>  
    <
input type="submit" name="test" value="TEST" />
 </
form

But it should be like this according to the w3s documentation

<form method="POST" action="" enctype="multipart/form-data">
    <
input type="file" name="files[]" size="20" multiple="multiple"/>  
    <
input type="submit" name="test" value="TEST" />
 </
form

I really appreciate that this library its useful to other people, please, be free to make any modifications according to your needs,.

 
Posted: 29 March 2012 07:01 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2009-11-27
5 posts

Modified this great library to enable optional file uploads ( no more “You did not select a file to upload.” messages )-
What you need to do is wrap upload process in “if” block at line 115:

replace

#Here we do the upload process
foreach ($uploaded_files as $file => $value{
    
if (!$this->do_upload($file)) {
        $uploaded_info[
'error'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
    
else {
        $uploaded_info[
'success'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
    
}

with

#Here we do the upload process
foreach ($uploaded_files as $file => $value{
    
if( $value['size'){
        
if (!$this->do_upload($file)) {
            $uploaded_info[
'error'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
        
else {
            $uploaded_info[
'success'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
        
}
    }
 
Posted: 18 May 2012 03:15 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
karlis_i - 29 March 2012 07:01 AM

Modified this great library to enable optional file uploads ( no more “You did not select a file to upload.” messages )-
What you need to do is wrap upload process in “if” block at line 115:

replace

#Here we do the upload process
foreach ($uploaded_files as $file => $value{
    
if (!$this->do_upload($file)) {
        $uploaded_info[
'error'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
    
else {
        $uploaded_info[
'success'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
    
}

with

#Here we do the upload process
foreach ($uploaded_files as $file => $value{
    
if( $value['size'){
        
if (!$this->do_upload($file)) {
            $uploaded_info[
'error'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
        
else {
            $uploaded_info[
'success'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
        
}
    }

Thanks for your contribution karlis_i

 
Posted: 23 May 2012 11:32 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2012-05-23
4 posts
karlis_i - 29 March 2012 07:01 AM

Modified this great library to enable optional file uploads ( no more “You did not select a file to upload.” messages )-
What you need to do is wrap upload process in “if” block at line 115:

replace

#Here we do the upload process
foreach ($uploaded_files as $file => $value{
    
if (!$this->do_upload($file)) {
        $uploaded_info[
'error'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
    
else {
        $uploaded_info[
'success'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
    
}

with

#Here we do the upload process
foreach ($uploaded_files as $file => $value{
    
if( $value['size'){
        
if (!$this->do_upload($file)) {
            $uploaded_info[
'error'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
        
else {
            $uploaded_info[
'success'][] array_merge($this->data(), array('error_msg' => $this->display_errors()));
        
}
    }

This is perfect! Exactly what I needed. Thank you.

 
Posted: 03 June 2012 04:14 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Joined: 2011-05-30
31 posts

Please Help me to create thumbnail also.

 
Posted: 08 June 2012 04:01 PM   [ Ignore ]   [ # 16 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
somenet - 03 June 2012 04:14 AM

Please Help me to create thumbnail also.

Hi, right know i’m at work but i’ve already worked with thumbnails creation, if you want or decide send me a private message with your email so i can send you an example on how to create thumbnails.

 
Posted: 09 June 2012 12:13 AM   [ Ignore ]   [ # 17 ]   [ Rating: 0 ]
Joined: 2012-06-09
1 posts

Hi romyblack!
  thanks for sharing this, i am also new here and trying to learn something everyday.

Get Facebook Fanzs

 
Posted: 09 June 2012 07:05 AM   [ Ignore ]   [ # 18 ]   [ Rating: 0 ]
Joined: 2011-05-30
31 posts

hi my email id is .(JavaScript must be enabled to view this email address)

 
Posted: 09 June 2012 08:28 PM   [ Ignore ]   [ # 19 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts

HI,

I UPDATED THE LIBRARY SO IT NOW ACCEPTS MULTIDIMENSIOAL AND BIDIMENSIONAL
FILES’ ARRAY smile

NOW WITH THE UPDATED LIBRARY YOU CAN DO THIS.

<form method="POST" action="" enctype="multipart/form-data">
<
input type="file" name="file[]" size="20" /> 
<
input type="file" name="file[]" size="20" />
<
input type="file" name="file1" size="20" />
<
input type="file" name="file2" size="20" />
<
input type="submit" name="test" value="TEST" />
</
form

YOU CAN USE EVEN HYBRIDS FILE INPUTS IF YOU DESIRE.

Here’s the link http://ellislab.com/forums/viewthread/207911/
Hope you enjoy, special thanks to every person who’s using this library.

MY_Paypal Library coming soon smile
This library will be the easiest to implement and everyone will be capable to handle payment process in their projects.

 
Posted: 14 June 2012 06:41 PM   [ Ignore ]   [ # 20 ]   [ Rating: 0 ]
Joined: 2012-04-15
10 posts

Romy,

This saved me a HUGE amount of time thank you. I have however run into a small issue. I want to save the filenames to a database but I cannot seem to figure out how to do so. Could you give me an example of how I would achieve this say with a table such as below

CREATE TABLE IF NOT EXISTS 'user_images' (
  
'id' int(11NOT NULL AUTO_INCREMENT,
  
'image_name' varchar(100NOT NULL,
  
PRIMARY KEY ('id')
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=

I forgot to mention this is my form

<?php echo form_open_mutlipart('site/upload');
      echo 
form_upload('userfile[]','','multiple="multiple"');
      echo 
form_submit('submit','Upload');
      echo 
form_close();
?> 
 
Posted: 14 June 2012 10:23 PM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
Ghetolobster - 14 June 2012 06:41 PM

Romy,

This saved me a HUGE amount of time thank you. I have however run into a small issue. I want to save the filenames to a database but I cannot seem to figure out how to do so. Could you give me an example of how I would achieve this say with a table such as below

Hi Ghetolobster, first at all thanks for taking this library in consideration to your projects.

When you do this proccess.

$uploaded $this->upload->up(TRUE); 

The $uploaded variable will contain an array with to more arrays, the SUCCESS files and the ERROR. so the SUCCESS contains the files that were uploaded correctly. so the only thing you have to do is to iterate and save it as you desire, for example.

foreach($uploaded['success'as $file){
 
echo $file['file_name'];

That’s all hope its useful for you. just save that value into your data base smile

 
Posted: 16 June 2012 05:51 AM   [ Ignore ]   [ # 22 ]   [ Rating: 0 ]
Joined: 2012-04-15
10 posts
Romyblack - 14 June 2012 10:23 PM
$uploaded $this->upload->up(TRUE);

foreach(
$uploaded['success'as $file){
 
echo $file['file_name'];

Romy,

Thank you so much for this, I used this code and did the following for entering into the database.

if (count($uploaded['success']) > 0)
{
    
foreach ($uploaded['success'as $file)
    
{
        $data 
= array (
            
'user_id' => $user_id,
            
'image_name' => $file['file_name']
        
);
   
        
$this->db->insert('user_images'$data);
    
}
 
Posted: 06 August 2012 08:14 AM   [ Ignore ]   [ # 23 ]   [ Rating: 0 ]
Joined: 2012-05-12
12 posts

Hello everybody,
My file was named MY_Upload, and paste in folder library.
NOT WORKq Message:
Fatal error: Call to undefined method CI_Upload::up() in D:\xampp\htdocs\fpc\application\controllers\Utz_c.php on line 64

Please help

 
Posted: 06 August 2012 08:23 AM   [ Ignore ]   [ # 24 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
ogib - 06 August 2012 08:14 AM

Hello everybody,
My file was named MY_Upload, and paste in folder library.
NOT WORKq Message:[removed]nullo();
Fatal error: Call to undefined method CI_Upload::up() in D:\xampp\htdocs\fpc\application\controllers\Utz_c.php on line 64

Please help

1) Make sure you pasted the file at ./application/libraries/MY_Upload.php
2) Confirm if your code is similar to this one.

$this->load->library('upload');

 
$config['upload_path']   './uploads'//if the files does not exist it'll be created
 
$config['allowed_types''gif|jpg|png|xls|xlsx|php|pdf';
 
$config['max_size']   '4000'//size in kilobytes
 
$config['encrypt_name']  TRUE;

 
$this->upload->initialize($config);

 
$uploaded $this->upload->up(TRUE); //Pass true if you want to create the index.php files 

3) Verify the config file that this variable has the correct value.

$config['subclass_prefix''MY_'
 
Posted: 06 August 2012 09:30 AM   [ Ignore ]   [ # 25 ]   [ Rating: 0 ]
Joined: 2012-05-12
12 posts

1) Make sure you pasted the file at ./application/libraries/MY_Upload.php

That was my mistake!
Many thanks!
Works perfectly!

 
1 of 3
1