Skip to content

Check file size for upload in supported browsers using HTML5 File API #450

Closed
@niftylettuce

Description

@niftylettuce

This is a mix between jquery-validation and Modernizr, although we can port the Modernizr part out so Modernizr is not a dependency.

I'm wondering if you are open to having me add it to additional-plugins? It is a great feature :)

  // Validate file input on change
  jQuery.validator.addMethod("filesize", function(value, element, param) {
    // This requires Modernizr filereader community add-on:
    // <https://github.com/Modernizr/Modernizr/blob/master/feature-detects/file-api.js>
    var valid = true;
    if (Modernizr.filereader) {
      // Check if file size is valid
      // (e.g. value = "10485760" = 10mb)
      for(var i=0;i<element.files.length;i+=1) {
        if (element.files[i].size > param) valid = false;
      }
    }
    return this.optional(element) || valid;
  }, "File exceeds maximum upload size.");

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy