This one goes out to all the code writers, web developers, and open source script fans.
This is a short script I built for a project, ended up opting to use individual AJAX uploads rather than multiple uploads at once. Yet a script this useful deserves to see the rest of the world so I give you.
Multiple File Uploads with JQuery and Code Igniter
To get it running extract into the root directory of a Code Igniter installation, included are:
- example Controller
- Multi-Upload Library
- example view form & success page with results
- jquery multi-upload plugin
The upload library is based upon the CI upload library, it will check for attacks, and check whether the files uploaded are images or something else. You can restrict the files to any extension(s), if you need more security than that then I’ll assume you know enough to add in the function you need.
The beauty of this script is the simplicity, with a few lines of code you can allow for multiple uploads from a single page, then let this script handle the uploads and pass on information about everything that happened.
If you are not familiar with Code Igniter it is a rather lightweight PHP MVC framework. Which is a geeky way of saying that it is a programming framework that can save you time without eating your server. Of course the same goes for JQuery, which is for Javascript framework that will save you time.
If you have any questions please leave a comment or ask me through the contact form.
Tags: Code Igniter, JQuery, Open Source
Awesome, your script is flawless! Plug“n play kind.
Awesome job to make it available for free and integrated with CI. Many thanks.
this is great library, it’s just what I needed but I have a problem;
it only works with this included jquery.MultiFile ! now, there is a newer version of this Multi file and when I use it it wont work. For example, I need to change “remove” string when removing selected image in some other language, and when i change it in your packed js file – the script won’t execute. you think you could solve this problem?
sorry, i solved this problem with MetaData plugin and now works great! Thanks again!
I am having problem using this library, I cannot see error messages when the script encounters errors. I have echoed the errors in view files and passed the error variable through the data array in view.
I have to change line 33 of the Multi_upload.php controller from
$num_files = count($_FILES[$field]['name']) -1;
to
$num_files = count($_FILES[$field]['name']);
for it to work with jQuery 1.3.1 (up from the 1.2.6 included) and jQuery Multiple File Upload Plugin
v1.46 (up from the v1.3 included).
thank you for the update, will get around to updating the released version at some point
I want to use multiple upload. Can you please help. Bcos example only shows 1 file upload.
For me, for jQuery 1.3.1 and CodeIgniter 1.7.1, this fantastic script doesn’t work correctly. MiniSOLVED:
In Multi_upload.php, Line 156:
if($error_hold[$i]==false) { // MOJA PRZEROBKA (jesli nie ma bledu pozwalamy na copy)
if ( ! @copy($CI->upload->file_temp, $CI->upload->upload_path.$CI->upload->file_name))
{
if ( ! @move_uploaded_file($CI->upload->file_temp, $CI->upload->upload_path.$CI->upload->file_name))
{
$error_hold[$i] = ‘upload_destination_error’;
}
}
}
instead of
if ( ! @copy($CI->upload->file_temp, $CI->upload->upload_path.$CI->upload->file_name))
{
if ( ! @move_uploaded_file($CI->upload->file_temp, $CI->upload->upload_path.$CI->upload->file_name))
{
$error_hold[$i] = ‘upload_destination_error’;
}
}
and, line 212: $CI->upload->set_error($error_hold); instead of $this->set_error($error_hold);
Thanks!
One bug with CI 1.7.2
In CI’s upload lib, Upload.php, comment out line 935
$filename = $this->file_name;
Not sure what this does anyway. Seems unnecessary.
Just wanted to say thanks for the script — worked perfectly and saved me tons of time! Thanks man