在JQuery File上传演示中限制文件类型

Fai*_*mon 22 jquery codeigniter file-upload blueimp

我正在使用Codeigniter的下一个项目使用JQuery文件上传演示.谁能告诉我如何实现以下目标:

  • 将上传文件类型限制为.zip和.rar
  • 限制文件大小
  • 清除上传文件列表(JQuery文件上传插件显示已上传文件的列表)

帮助赞赏!!

Dav*_*.id 67

你现在可能有很多解决方案,但是我想使用BASIC插件来获取jquery上传器,即没有任何其他脚本..由于某种原因,maxFileSize/fileTypes选项不起作用 - 但这对我的缺乏来说无疑是毋庸置疑的阅读文档!

无论如何,对我而言,它与以下内容一样快:

    add: function (e, data) {
        var goUpload = true;
        var uploadFile = data.files[0];
        if (!(/\.(gif|jpg|jpeg|tiff|png)$/i).test(uploadFile.name)) {
            common.notifyError('You must select an image file only');
            goUpload = false;
        }
        if (uploadFile.size > 2000000) { // 2mb
            common.notifyError('Please upload a smaller image, max size is 2 MB');
            goUpload = false;
        }
        if (goUpload == true) {
            data.submit();
        }
    },
Run Code Online (Sandbox Code Playgroud)

因此,只使用ADD选项仅允许正则表达式中的图像类型,并检查(在我的情况下)文件大小最大为2mb.

相当基本,再次我确信maxFileSize选项有效,只是我只包括基本的插件脚本jquery.fileupload.js

编辑 我应该添加在我的情况下我只上传一个文件(一个配置文件图像)所以因此data.files [0] ..你可以迭代文件集合当然.


Pot*_*eek 7

在jquery.fileupload-ui.js中编辑此部分:

   $.widget('blueimp.fileupload', $.blueimp.fileupload, {

    options: {
        // The maximum allowed file size:
        maxFileSize: 100000000,
        // The minimum allowed file size:
        minFileSize: undefined,
        // The regular expression for allowed file types, matches
        // against either file type or file name:
        acceptFileTypes:  /(zip)|(rar)$/i,
        ----------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

清除上传文件列表 - 如果您不需要该功能,请从main.js中删除$ .getJSON调用.


Sat*_*tya -2

尝试看看这一行:

 process: [
            /*
                {
                    action: 'load',
                    fileTypes: /^image\/(gif|jpeg|png)$/,
                    maxFileSize: 20000000 // 20MB
                },
                {
                    action: 'resize',
                    maxWidth: 1920,
                    maxHeight: 1200,
                    minWidth: 800,
                    minHeight: 600
                },
Run Code Online (Sandbox Code Playgroud)

在 jquery.fileupload-fp.js 中