EllisLab text mark
Advanced Search
2 of 3
2
   
Multiple file upload library
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!

 
Posted: 08 August 2012 09:41 AM   [ Ignore ]   [ # 26 ]   [ Rating: 0 ]
Joined: 2012-08-07
1 posts

It is really a special one. I like the way you have presented the information. Interesting post. Thanks for sharing

wind meter

 
Posted: 08 August 2012 09:45 AM   [ Ignore ]   [ # 27 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
Rachel Gawith - 08 August 2012 09:41 AM

It is really a special one. I like the way you have presented the information. Interesting post. Thanks for sharing

Thank you Rachel, smile just in case, put romyblack in the search forum field and you’ll find some libraries i’ve build, like the easiest paypal library for CI. smile

 
Posted: 18 August 2012 09:45 AM   [ Ignore ]   [ # 28 ]   [ Rating: 0 ]
Joined: 2012-08-18
1 posts

Hi.. Thank you for making the extended library for uploading files.. I tried to use your extended library, but unfortunately I got an error.. I wonder if you could help me resolve this.. Thanks a bunch..

(This is my error message)
A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: -1

Filename: libraries/MY_Upload.php

Line Number: 85

(And this is what I wrote on my controller)

$config['upload_path''./image/upload/';
$config['allowed_types'"jpg|png";
$config['max_size''100000';
$config['max_width']  '6000';
$config['max_height']  '6000';

$this->load->library('upload'$config);
$uploaded $this->upload->up(FALSE);
  
foreach(
$uploaded['success'as $file){
   
echo $file['file_name'];


EDIT :
My bad.. The upload path should be like ‘./image/upload’ instead of ‘./image/upload/’.. Thx anyway..

 
Posted: 21 August 2012 05:14 PM   [ Ignore ]   [ # 29 ]   [ Rating: 0 ]
Joined: 2012-08-21
3 posts

Just registered to say this was exactly what I was looking for, thank you very much. I do however run in a minor issue, if there are multiple entries in the “error” array (the files that did not get uploaded) their error messages are concatenated, like this (I’m echoing the file names and the error messages):

  (filename1)

  The file you are attempting to upload is larger than the permitted size.
 
  (filename2)

  The file you are attempting to upload is larger than the permitted size.

  The file you are attempting to upload is larger than the permitted size.

So the first error message under filename2 is actually the error message of filename1. I found out this happens because for uploading all the files, one instance of the upload class is used, and the error messages are just added together (because one file can have multiple error messages). It can be fixed by clearing the error array after merging it in the $uploaded_info, like this:

#Here we do the upload process
   
foreach($_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()));
      
$this->error_msg = array();
      
     
}
     else{
      $uploaded_info[
'success'][] =  array_merge($this->data(),
          array(
'error_msg' => $this->display_errors()));
      
$this->error_msg = array();
     
}
    }
   } 
 
Posted: 22 August 2012 02:25 AM   [ Ignore ]   [ # 30 ]   [ Rating: 0 ]
Joined: 2011-05-30
31 posts

Dear friend,I need the thumbnail of the picture also how should i configure the code to get the thumbnail also.

 
Posted: 22 August 2012 05:45 AM   [ Ignore ]   [ # 31 ]   [ Rating: 0 ]
Joined: 2012-08-21
3 posts
somenet - 22 August 2012 02:25 AM

Dear friend,I need the thumbnail of the picture also how should i configure the code to get the thumbnail also.

That’s somewhat outside the scope of this topic I think, but take a look at the Image Manipulation class: http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html

 
Posted: 05 October 2012 02:25 AM   [ Ignore ]   [ # 32 ]   [ Rating: 0 ]
Joined: 2012-09-14
18 posts

Thanks for the library.

I have one question. In case I need identify what was the input field used by the user to upload a given file, what I must do? I mean, I have a form with three file input fields, and users can upload one of them, the my backend logic is different and tied to what input field the user select.

Thanks in advanced.
Frank

 
Posted: 14 October 2012 01:48 AM   [ Ignore ]   [ # 33 ]   [ Rating: 0 ]
Joined: 2011-04-11
27 posts

Hi Nihilistik,

I just wanted to say thanks for making this nice piece of code. I’ve incorporated into my CI app and it is working great. I’ve been looking for this for over a year so it is a HUGE help. Hopefully it will continue to help others too, thanks again!

best regards,
tim

 
Posted: 20 October 2012 11:33 PM   [ Ignore ]   [ # 34 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
Pent - 21 August 2012 05:14 PM

Just registered to say this was exactly what I was looking for, thank you very much. I do however run in a minor issue, if there are multiple entries in the “error” array (the files that did not get uploaded) their error messages are concatenated, like this (I’m echoing the file names and the error messages):

  (filename1)

  The file you are attempting to upload is larger than the permitted size.
 
  (filename2)

  The file you are attempting to upload is larger than the permitted size.

  The file you are attempting to upload is larger than the permitted size.

So the first error message under filename2 is actually the error message of filename1. I found out this happens because for uploading all the files, one instance of the upload class is used, and the error messages are just added together (because one file can have multiple error messages). It can be fixed by clearing the error array after merging it in the $uploaded_info, like this:

Hi my friend, thanx for using my library and give me this information, im really sorry i did not answered you in the propper time, i was without pc for a wile. ill analize what you are trying to tell me and resolve this issue.

 
Posted: 20 October 2012 11:35 PM   [ Ignore ]   [ # 35 ]   [ Rating: 0 ]
Joined: 2012-01-05
24 posts
frankabel - 05 October 2012 02:25 AM

Thanks for the library.

I have one question. In case I need identify what was the input field used by the user to upload a given file, what I must do? I mean, I have a form with three file input fields, and users can upload one of them, the my backend logic is different and tied to what input field the user select.

Thanks in advanced.
Frank

Hi that’s a good question. ill see how we can fix this as soon as posible, im sorry i haven’t answer for you early. but here i am, back to action.

 
2 of 3
2