在移动端某地地方需要上传图片,找了一个比较简洁好用的上传工具,这个工具操作很简单。EasyUploader上传文件
<script src="/static/mall/lib/jquery-2.1.4.js"></script>
<script type="text/javascript" src="/static/com/easyuploader/easyuploader.min.js"></script>
<script>
var eu = new EasyUploader({
'file': '#uploaderInput',//input[type='file']的方式
'url': './upload.php',
'autoUpload': true,
'language': 'en',
'compress': true,
'resize': {
'maxWidth': 1000,
'maxHeight': 1000
},
'compressQuality': 0.9,
'maxFileSize': '10M',
onUploadProgress: function (e) {
console.log('the progress:' + ((e.loaded / e.total) * 100).toFixed(2) + '%');
},
onUploadStart: function (e) {
console.log('the file will upload');
},
onUploadComplete: function (data) {
console.log('data',data)
alert(data.msg);
if (data.code == 1) {
fileData = data.data;
if (fileData.file_type.indexOf('image/') >= 0) {
img.src = fileData.path;
fileFrameObj.appendChild(img);
} else {
div.innerHTML = 'the file path:' + fileData.path;
fileFrameObj.appendChild(div);
}
}
},
onUploadError: function (statusCode) {
console.log(statusCode);
}
});
</script>更多看demo(包含js):