Created
September 29, 2012 16:58
-
-
Save jonatanfroes/3804579 to your computer and use it in GitHub Desktop.
Codeigniter + Jquery File Upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function save_photo($galleries_id = 0, $item_id = 0, $redirect = '') | |
{ | |
// aqui vc faz o upload normal, com a classe upload do CodeIgniter | |
// É passado o $_FILES['Filedata'] | |
// vc precisa retornar um json + ou - assim: | |
$this->output->enable_profiler(FALSE)->set_output(json_encode( | |
array('status' => $res ? TRUE : FALSE, | |
'message' => 'ok', | |
'name' => 'arquivo'))); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- configure a url que irá receber os dados --> | |
<input id="fileupload" type="file" name="Filedata" data-url="<?php echo site_url('admin/portfolio/save_photo/' . $gallery->id); ?>" multiple /> | |
<div id="progress" class="progress progress-striped active"> | |
<div class="bar" style="width: 0;"></div> | |
</div> | |
<div id="upload_result"></div> | |
<hr /> | |
<!-- /end multiple upload --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#fileupload').fileupload({ | |
submit: function (e, data) { | |
//usei um plugin p/ bloquear a página enquanto o upload acontece. Pode remocer a linha abaixo | |
$.blockUI({ message: '<h3>' + processing + '</h3>' }); | |
}, | |
stop : function(e, data) { | |
window.location='<?php echo site_url(uri_string()); ?>'; | |
setTimeout($.unblockUI, 100); //pode remover | |
$('#progress').slideUp('slow').remove(); | |
$('#upload_result').html('<?php echo msg('info', anchor(uri_string(), " <strong>'+items_uploaded+' </strong>" . lang('portfolio_nr_files_uploaded') . ' ' . lang('portfolio_click_to_see_changes'))) ; ?>').slideDown('slow'); //configure nesta linha a msg no final do upload | |
items_uploaded = 0; | |
}, | |
sequentialUploads: true, | |
acceptFileTypes : '/(\.|\/)(bmp|gif|jpe?g|jpe|png|bmp)$/i', | |
dataType: 'json', | |
progressall: function (e, data) { | |
var progress = parseInt(data.loaded / data.total * 100, 10); | |
$('#progress .bar').css( | |
'width', | |
progress + '%' | |
); | |
}, | |
done: function (e, data) { | |
items_uploaded++; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment