duannao1920 2012-11-21 09:38
浏览 67
已采纳

jQuery文件上传 - 配置和运行

I'm using this plugin: jQuery File Upload

My 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>

My 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();
                });

});

Things I'd love to achieve:

  1. Resizing images at client side
  2. Then send images with additional form data (data are not comming to server side script) to upload.php

Thanks a lot in advance.

  • 写回答

2条回答 默认 最新

  • dqlm80253 2012-12-18 10:39
    关注

    Jquery File upload is not the right choice for my request. I'm now successfully using Plupload.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料