Giter VIP home page Giter VIP logo

whathave / file-uploader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from valums-file-uploader/file-uploader

0.0 2.0 0.0 709 KB

Multiple file upload plugin for HTML forms. User-friendly progress-bar + uploads via drag-and-drop. Coded in Javascript + AJAX, not Flash. Server-side PHP, Java, & ColdFusion examples included.

Home Page: http://valums-file-uploader.github.com/file-uploader/

License: Other

HTML 15.84% CSS 2.59% JavaScript 70.20% Java 2.62% ColdFusion 2.67% Perl 0.99% PHP 5.09%

file-uploader's Introduction

Notice:
This project made some improvements to Valum's initial AJAX uploader, but it is no longer actively maintained. Some bugs may remain unfixed. A commercial fork of this project (with a licencing fee) with many bugfixes is available at http://fineuploader.com/.
Interested maintainers for this project may post on the issues forum.

Valum's File Uploader v2.0 beta

Welcome! This project attempts to achieve a user-friendly file-uploading experience over the web. It's built as a Javascript plugin for developers looking to incorporate file-uploading into their website.

This is a public fork of Valum's File Uploader (v1) in an attempt to incorporate some of the best bugfixes and patches to make a version compatible with the latest browsers in 2012.

We would love developers to contribute any improvements and bugfixes they produce. See How do I contribute to other's code in GitHub?.

Initiated by SimonEast, but interested maintainers are welcome.

Summary

This plugin uses an XMLHttpRequest (AJAX) for uploading multiple files with a progress-bar in FF3.6+, Safari4+, Chrome and falls back to hidden-iframe-based upload in other browsers (namely IE), providing good user experience everywhere.

It does not use Flash, jQuery, or any external libraries.

Features

  • Multiple file select, progress-bar in FF, Chrome, Safari
  • Drag-and-drop file select in FF, Chrome
  • Uploads are cancellable
  • No external dependencies
  • Doesn't use Flash
  • Fully working with HTTPS
  • Keyboard support in FF, Chrome, Safari
  • Tested in IE7/8, Firefox 3/3.6/4, Safari 4/5, Chrome, and Opera 10.60

License

This plugin is open sourced under GNU GPL 2 or later and GNU LGPL 2 or later.

Known Issues

Plugin breaks back button functionality in Opera.

Getting started

The fileuploader.js contains two classes that are meant to be used directly. If you need a complete upload widget (from demo) to quickly drop into your current design, use qq.FileUploader.

If you want to customize uploader, by using a different looking file list or change the behaviour or functionality use qq.FileUploaderBasic.

The difference between them is that qq.FileUploader provides a list of files, drag-and-drop, but qq.FileUploaderBasic only creates button and handles validation. Basic uploader is easier extendable, and doesn't limit possible customization.

qq.FileUploader extends qq.FileUploaderBasic, so that all the options present in the basic uploader also exist in the full widget.

qq.FileUploader - Setting up full upload widget

Include fileuploader.js and fileuploader.css into your page. Create container element.

<div id="file-uploader">       
<noscript>          
    <p>Please enable JavaScript to use file uploader.</p>
    <!-- or put a simple form for upload here -->
</noscript>         
</div>

Initialize uploader when the DOM is ready. Change the action option. For example ../server/php.php for the default folder structure. In the server folder you will find examples for different platforms. If you can't find the one you need, check the readme.txt in the same folder.

var uploader = new qq.FileUploader({
	// pass the dom node (ex. $(selector)[0] for jQuery users)
	element: document.getElementById('file-uploader'),
	// path to server-side upload script
	action: '/server/upload'
}); 

Options of both classes

    // url of the server-side upload script, should be on the same domain
    action: '/server/upload',
    // additional data to send, name-value pairs
    params: {},
    
    // validation    
    // ex. ['jpg', 'jpeg', 'png', 'gif'] or []
    allowedExtensions: [],        
    // each file size limit in bytes
    // this option isn't supported in all browsers
    sizeLimit: 0, // max size   
    minSizeLimit: 0, // min size
    abortOnFailure: true, // Fail all files if one doesn't meet the criteria
    
    // set to true to output server response to console
    debug: false,
    
    // events         
    // you can return false to abort submit
    onSubmit: function(id, fileName){},
    onProgress: function(id, fileName, loaded, total){},
    onComplete: function(id, fileName, responseJSON){},
    onCancel: function(id, fileName){},
    onError: function(id, fileName, xhr){}
    
    messages: {
        // error messages, see qq.FileUploaderBasic for content            
    },
    showMessage: function(message){ alert(message); }        

Instance methods

  • setParams(newParams)

Changing alert/messages to something more user friendly

If you limited file types and max size, you will probably want to change the default alert and messages as you see fit, this is possible using showMessage callback and messages option.

Sending additional params

To add a parameter that will be passed as a query string with each upload use params option.

    var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader'),
        action: '/server-side.upload',
        // additional data to send, name-value pairs
        params: {
            param1: 'value1',
            param2: 'value2'
        }
    });

To change params based on the state of your app, use

    uploader.setParams({
       anotherParam: 'value' 
    });

It can be nicely used in onSubmit callback.

Troubleshooting

If you can't get the uploader to work, please try the following steps before asking for help.

If the upload doesn't complete, saying "failed":

  • Set the debug option of the FileUploader to true.
  • Open the page where you have a FileUploader.
  • Open developer console in your browser.
  • Try to upload the file. You should see a server serponse.

It should be {success:true} for completed requests. If it's not, then you have a problem with your server-side script.

Contributors

Thanks to everybody who contributed, either by sending bug reports or donating. And special thanks to:

John Yeary
Sidney Maestre
Patrick Pfeiffer
Sean Sandy (SeanJA)
Andy Newby
Ivan Valles

file-uploader's People

Contributors

asturur avatar bencolon avatar benruijl avatar bjansen avatar danielbeardsley avatar doomhz avatar ebrentnelson avatar gsouf avatar hlship avatar jackdanger avatar justinvw avatar kir avatar pegweb avatar richsage avatar seanja avatar simoneast avatar sstur avatar texasassetprotection avatar thinkscape avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.