jQuery plugin for upload a image, simple and elegant.
upload a image return image url and custom data. click image button upload, display progress percent, finish display this image into image button.
Demo http://www.chengxufan.com/codes/jquery.singleuploadimage.js/example
- Include jQuery follwed by
jQuery.singleuploadimage.js
. There is also a minified script include.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="jQuery.jTableCheckbox.min.js"></script>
- Add
div
andinput
in your html.
<div id="uploadbox" onClick="singleupload_input.click();" class="singleupload"></div>
<input type="file" id="singleupload_input" style="display:none;" name="img" value=""/>
- Add
css style
a class of.singleupload
.
.singleupload {
background: url(empty_bg.png);
border:1px solid #ccc;
text-align: center;
width: 92px;
height: 92px;
line-height: 92px;
}
- Add
script
.
$(function() {
$('#uploadbox').singleupload({
action: 'do_upload.php', //action: 'do_upload.php'
inputId: 'singleupload_input',
onError: function(code) {
console.debug('error code '+res.code);
}
/* ,onSucess: function(url, data) {} */
/*,onProgress: function(loaded, total) {} */
});
});