CodeIgniter - Multiple file uploads using dynamic field generation -
im using jquery script add new file upload fields form dynamically, result, file fields so
<input class="file-input-area" name="mpfile[]" type="file" size="32" value="" /> so in other words, if click 'add more file upload' link 5 times, 5 file upload fields 1 above.
iam quite new codeigniter , have done research tells me if uploading multiple files, should use [] after field name ... hope right.
my problem figuring process upload files, , store names database table.
i have tried normal php uploading doesnt seem working, im not sure put in view, controller , model.
if can give me example of how go it, me much.
cheers,
use jquery uploadify. files uploaded asynchronously, see demos here.
here's implementation:
jquery('#images').uploadify({ 'uploader' : '/uploadify/uploadify.swf', 'script' : '/uploadify/uploadify.php', 'cancelimg' : '/uploadify/cancel.png', 'folder' : '/data/images', 'auto' : true, 'fileext' : '*.jpg;*.gif;*.png;*.jpeg;*.tif', 'filedesc' : 'web image files (.jpg, .gif, .png, .jpeg, .tif)', 'queueid' : 'images-queue', 'oncancel' : function(event,id,fileobj,data) { jquery.ajax({ type: "post", url: "uploadify/delete_image.php", data: "filepath=/data/images/" + jquery("#"+id).val(), success: function(){ jquery("#"+id).remove(); queuesize = data.filecount; jquery('#status-message').text('photo uploaded!'); } }); }, 'onselect' :function (event, id) { if (queuesize < maxqueuesize) queuesize++; else{ alert("max number of files " + maxqueuesize); jquery('#images').uploadifycancel(id); return false; } }, 'onselectonce' : function(event,data) { jquery('#status-message').text('file uploaded...'); }, 'oncomplete': function (evt, queueid, fileobj, response, data) { jquery('#status-message').text('h φωτογραφία φορτώθηκε!'); jquery("#field_photos").append("<input id="+ queueid +" type='hidden' name='pics[]' value='" + response + "' />"); //adds hidden form field }, 'onallcomplete' : function(event,data) { }, 'onclearqueue' : function (a, b) { queuesize = 0; }, 'multi' : true, 'simuploadlimit' : 3, 'removecompleted': false, 'sizelimit' : 1048576, 'queuesizelimit' : 1 }); with line:
jquery("#field_photos").append("<input id="+ queueid +" type='hidden' name='pics[]' value='" + response + "' />"); //adds hidden form field we store filenames in hidden array field "pics". when form submitted, read these names using $this->input->post('pics') , store them database.
Comments
Post a Comment