Drag and Drop uploader with CodeIgniter
2011-11-07 08:58:23
I’ve spent a little bit of time here and there trying to get a jQuery powered drag n drop uploader working well with the Upload library within CodeIgniter. Most of the fumbling has been due to my own misunderstanding of what goes on in the background.
Fortunately, I’ve overcome that obstacle.
I cloned abailiss’ jQuery-drag-drop plugin from Github, and placed the appropriate files in their locations (js file into my /assets/js/ folder and the view in /views/). Within the Controller function which is pointed at by the uploadUrl that is set in the .dropUpload() instantiation, I placed:
$config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc'; $config['max_size'] = '242048'; $config['max_width'] = '0'; $config['max_height'] = '0'; $config['remove_spaces'] = 'TRUE'; $this->upload->initialize($config); foreach($_FILES as $k => $f): $this->upload->do_upload($k); endforeach;
I’ll be adding a line to pass the data to a model for Database saving - but that worked beautifully for me for uploading multiple files via drag and drop.