我正在使用这个插件:jQuery 文件上传
我的 HTML:
<input id="fileupload" type="file" name="files[]" data-url="upload.php" multiple>
<script src="/js/vendor/jquery.ui.widget.js"></script>
<script src="/js/jquery.iframe-transport.js"></script>
<script src="/js/jquery.fileupload.js"></script>
<script src="http://blueimp.github.com/JavaScript-Load-Image/load-image.min.js"></script>
<script src="http://blueimp.github.com/JavaScript-Canvas-to-Blob/canvas-to-blob.min.js"></script>
<script src="/js/jquery.fileupload-fp.js"></script>
<div id="dropzone" class="fade well">Drop files here</div>
我的 JS:
$(document).ready(function() {
$('#fileupload').fileupload({
dataType: 'json',
dropZone: $('#dropzone'),
singleFileUploads: false,
add: function (e, data) {
$(this).fileupload('process', data).done(function () {
data.submit();
});
},
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
},
process: [
{
action: 'load',
fileTypes: /^image\/(gif|jpeg|png)$/,
maxFileSize: 20000000 // 20MB
},
{
action: 'resize',
maxWidth: 1920,
maxHeight: 1080
},
{
action: 'save'
}
]
});
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
// The example input, doesn't have to be part of the upload form:
var GAL = $('#galleryId');
data.formData = {
galleryId: GAL.val(),
type: 'gallery',
entityId: 1
}
return true;
});
$(document).bind('dragover', function (e) {
var dropZone = $('#dropzone'),
timeout = window.dropZoneTimeout;
if (!timeout) {
dropZone.addClass('in');
} else {
clearTimeout(timeout);
}
if (e.target === dropZone[0]) {
dropZone.addClass('hover');
} else {
dropZone.removeClass('hover');
}
window.dropZoneTimeout = setTimeout(function () {
window.dropZoneTimeout = null;
dropZone.removeClass('in hover');
}, 100);
});
$(document).bind('drop dragover', function (e) {
e.preventDefault();
});
});
我想实现的目标:
- 在客户端调整图像大小
- 然后将带有附加表单数据的图像(数据未发送到服务器端脚本)发送到upload.php
提前非常感谢。