javascript - AJAX file upload fails -
i can't upload files described in several tutorials followed multiple guides here on stackoverflow, everytime ajax error.
my html form in codeigniter , following:
<?php echo form_open_multipart($this->uri->uri_string(), 'class="form-horizontal"'); ?> <fieldset> <div class="control-group <?php echo form_error('gid') ? 'error' : ''; ?>"> <?php echo form_label('image gallery', 'athletes_gid', array('class' => 'control-label')); ?> <div class='controls' > <input id='athletes_gid' type='file' name='athletes_gid[]' multiple value="<?php echo set_value('athletes_gid[]', isset($athletes['gid']) ? $athletes['gid'] : time()); ?>" /><br/><br/> <div id="addimg" class="btn">add images</div><br/><br/> <input type="submit" name="save" class="btn btn-primary" value="<?php echo lang('athletes_action_edit'); ?>" /> </fieldset> <?php echo form_close(); ?>
basicly normal file input field. , jquery goes like:
//ajax img upload // variable store files var files; // add together events $('#athletes_gid').on('change', prepareupload); // grab files , set them our variable function prepareupload(event) { files = event.target.files; } //so have formdata object, ready sent along xmlhttprequest. $( "#addimg" ).click(function() { var info = new formdata(); $.each(files, function(key, value) { data.append(key, value); }); $.ajax({ url: "/public/index.php/admin/content/athletes/multiupload", data: {data: json.stringify(data), ci_csrf_token: $("input[name=ci_csrf_token]").val()}, cache: false, contenttype: false, processdata: false, type: 'post', success: function(data){ alert(data); } }); });
if click on button "add images" after added image files upload, nothing... read somewhere firefox doesn't contenttype: false
not sure...
well, javascript can't access filesystem obvious security reasons.
what in cases, creating hidden iframe , submit form targeting frame. javascript i'm able read iframe html, , know result of upload.
another solution, hidden swf ( flash ) accessed javascript , upload task using swf.
javascript html ajax codeigniter
No comments:
Post a Comment