Welcome Guest, Not a member yet? Register   Sign In
Multiple file upload library
#1

[eluser]Romyblack[/eluser]
Hi Everyone.

I'm new at this and am a fan of this incredible CodeIgniter Framework,
here i share with you this libraries to upload multiple files, it have been
documented for easy integration.

I hope this is useful for you.

/*UPDATED 6/9/2012
I updated the library according to your need now you can upload with file arrays or normal file inputs as well, hope you enjoy. If you find this library helpful please say thanks and share it with people you know need this.
***********************************
/*UPDATED 21/10/2012
Hi everybody, i modified this library as you requested, first at all.
Special thanks to frankabel and Pent to help me improve this library, ok
so now the problem with the appended texts of error was resolved and now, the array that
the library returns has a new attribute called [FILE_INPUT] which tells you from which input field the file was submitted or selected.

Example Code
Code:
'file_name' => string 'NCF_BLOQUEADOS.txt' (length=18)
'file_type' => string 'text/plain' (length=10)
'file_path' => string 'C:/wamp/www/code/uploads/' (length=25)
'full_path' => string 'C:/wamp/www/code/uploads/NCF_BLOQUEADOS.txt' (length=43)
'raw_name' => string 'NCF_BLOQUEADOS' (length=14)
'orig_name' => string '' (length=0)
'client_name' => string 'NCF_BLOQUEADOS.txt' (length=18)
'file_ext' => string '.txt' (length=4)
'file_size' => float 1199.88
'is_image' => boolean false
'image_width' => string '' (length=0)
'image_height' => string '' (length=0)
'image_type' => string '' (length=0)
'image_size_str' => string '' (length=0)
'error_msg' => string '<p>El archivo que está tratando de subir excede el tamaño permitido</p>' (length=73)
'file_input' => string 'file' (length=4)

I hope you enjoy.

Cordially,
Romyblack.


Quote:Save this with this name (MY_Upload.php)
Click here: DOWNLOAD MY_Upload.php

Quote:PayPal library released Smile see post <here>
#2

[eluser]mattsmith[/eluser]
Thanks a bunch! This saved me like an hour of obnoxious work.
I did get a vague permissions error when trying to create the index.php files(but I didn't need those).
#3

[eluser]Romyblack[/eluser]
[quote author="mattsmith" date="1327013800"]Thanks a bunch! This saved me like an hour of obnoxious work.
I did get a vague permissions error when trying to create the index.php files(but I didn't need those).[/quote]

You're welcome, you can modify the library to your needs, the problem you're having is because of the file's permission.

In the console try this.

if the folder where you want the files to be uploaded is downloads
Code:
chmod +rw downloads

The script will have permissions to write a file on it Smile

Hope this help.
#4

[eluser]mattsmith[/eluser]
No, the upload directory was already set to 777. If that were the problem, it wouldn't be able to upload the files themselves.
#5

[eluser]Unknown[/eluser]
Huge help thanks for this.
#6

[eluser]Romyblack[/eluser]
[quote author="sony144" date="1327187937"]Huge help thanks for this.[/quote]

No problem, its a pleasure to help you with this little thing.

I feel very good Smile
#7

[eluser]pierrest[/eluser]
Hello everybody,

This library was workin perfect on my dev server, but now just deploying my project to the production server and i get this message

Call to undefined method CI_Upload::up()

my controller:
Code:
&lt;?php

class Upload extends CI_Controller {

function __construct()
{
  parent::__construct();
  $this->load->helper(array('form', 'url'));
}

function index()
{
  $this->load->view('admin/modify_module', array('error' => ' ' ));
  
  $this->load->library('session');
  $this->load->library('encrypt');
  $this->data['username'] = $this->session->userdata('user');
}
function do_upload_member() {
   $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

  $this->load->model('members');
   if ($this->input->post('submit')) {
    $this->members->add_member($uploaded);
   }
  $data['pagetitle'] = " Adhésion";
  $data['pageref'] = 'Nous avons bien reçu votre demande';
  $this->load->view('head', $data);
  $this->load->view('confirmation');
}



}
?&gt;

have been for a while on it and i am lost...

i have some rewriting htaccess stuff too which was not on the dev server:
(there is an evil joomla project on the same sever (which i did not develop myself) i use a subdomain for CI)

php_flag "allow_url_fopen" "On"
php_flag "allow_url_include" "On"

#AuthType Basic
#AuthName "Le site est en maintenance, veuillez repasser plus tard"
#AuthUserFile /home/www/c5f672d79af39528e95ff68c3587e35e/web/members/.htpasswd

#<Files index.php>
#require valid-user
#</Files>

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]


is it this rewrite which may causing the problem?

Thanks a lot if you can help me
#8

[eluser]Romyblack[/eluser]
[quote author="pierrest" date="1328542923"]

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]


is it this rewrite which may causing the problem?

Thanks a lot if you can help me[/quote]

Hi pierrest, please verify that you paste the library in the correct folder and named like this
MY_Upload.php, remember that when you put this library in your library folder, (not the core's library folder), it calls it automatically and override the functions with the same name.

Another thing, to confirm if your .htaccess is the problem, in your upload controller, call another library to see if it works property, if not then the problem is the .htaccess. if yes we'd better find another solution.

let us know the results.
#9

[eluser]InsiteFX[/eluser]
Some servers are case sensitive and need all filenames in lower case!
#10

[eluser]pierrest[/eluser]
File was named MY_upload and not MY_Upload.... :red:

It works now, library found, but it return nothing => bool(false)

... but the files are uploaded at the right place

EDIT: The problem was me again...=> i commented the whole if condition at line 113 of MY_Upload (#Here we do the upload process) to let the upload optional.


sorry to disturb for such things....




Theme © iAndrew 2016 - Forum software by © MyBB