GithubHelp home page GithubHelp logo

uploadmanager's Introduction

uploadManager

Mootools html5/ajax multipart file upload

Demo Screenshot

How to use

uploadManager uploads files in a temporary folder of your webserser and pull back the uploaded file name and its path in the form, so you can send them along with the rest of the form. you will need a webserver with php installed to run the demo. for a detailed usage see HOWTO.md in the Docs folder.

uploadManager

creates and manage uploads with the following features:

  • easy to use
  • Select files and upload folders from the file browser dialog (tested in chrome 20+)
  • folder drag drop (currently supported by chrome 21+)
  • file drag drop (currently supported by chrome 5+, firefox 3.6+ and safari 5.1+, IE10, Opera 12+)
  • faster upload: each file has multiple chunks uploaded in parallel (Google Chrome, Firefox 3.6+, Opera 12.5+, IE10)
  • resume upload on error/pause (Google Chrome, Firefox 4.0+, Opera 12.5+, IE10)
  • optional progressbar for browsers supporting HTML5 File API (chrome5+, safari4+, Firefox 3.6+, IE10, Opera 12 (Next))
  • no input file for Firefox 4+
  • iframe for older browsers
  • customizable by css (fully customizable in firefox 4 and later)
  • supports localization

uploadManager Property: resume

(boolean) indicates if the browser can resume upload after error or pause.

uploadManager Property: xmlhttpupload

(boolean) indicates if the browser handle file upload via XMLHTTPRequest.

uploadManager Property: enqueue

(boolean) queue upload. by default upload are not queued.

uploadManager Property: concurrent

(int) limit the number of active uploads if enqueue is true. default to 1

uploadManager Property: multiple

(boolean) indicates if the browser can handle multiple files selection.

uploadManager Method: upload {#uploadManager:upload}


create a new upload field in a given container.

Returns:

  • (object) - file upload instance. if the the maximum number of files that can be uploaded is reached null is returned instead.

Arguments:

  1. options - (object) see file upload instance options.
Options:
  • container - (string) upload container id.
  • folder - (boolean) Select folders instead of files in the file selection dialog. (Chrome 22+)
  • pause - (boolean) allow user to pause/resume upload (if the browser can resume broken upload) otherwise the resume button will only appear when an error occur. default to false.
  • chunks - (int) number of chunks uploaded simultaneously for a file. default to 3.
  • chunckSize - (int) chunk file size. default to 1Mb. if the browser can resume broken file upload, file will be split in pieces of a maximum length of chunckSize.
  • base - (string, optional) url of the page that will handle server side file upload. default to upload.php.
  • limit - (int, optional) maximum number of files the user can upload. 0 means no restriction. default to 0.
  • filesize - (int, optional) maximum size of a file the user can upload. 0 means no restriction. default to 0.
  • maxsize - (int, optional) maximum size of files uploaded by a user. 0 means no restriction. default to 0.
  • iframe - (boolean, optional) force iframe upload.
  • multiple - (boolean, optional) enable multiple file selection if the browser can handle it.
  • filetype - (string, optional) authorized file type.
  • name - (string) name of the upload form field. it contains the original name of the file sent by the user. if the upload succeed a hidden field named 'file_' + name and containing the encrypted file path on the server will be pushed into the form. if multiple file upload is enabled then this field will be sent as an array for example if our form field is named name[], then name[] will contains the original file name and file_name[] will contains the encrypted file path on the server.
  • progressbar - (mixed, optional) indicates whether to display a progressbar or not. if false then the progressbar is disabled. if true the progressbar will use default options. if it is an object, it will be passed as progressbar options. see Progressbar
  • hideDialog - (boolean, optional) Firefox 4+ only: if true the file selection dialog will not be shown after the upload instance is created.
  • autostart - (boolean, optional) automatically start upload. default to true.
Progressbar:
  • container - (mixed) progressbar container.
  • width - (int, optional) progressbar width.
  • value - (number, optional) initial value of the progressbar. value is always between 0 and 1 (100%). default to 0.
  • text - (string, optional) progressbar text.
  • color - (string, optional) progressbar color.
  • fillColor - (string, optional) progressbar fill color.
  • backgroundImage - (string, optional) background image used to fill the progressbar. this parameter will shadow the fillColor parameter.
Progressbar events:
onChange
Arguments:
  • value - (number) progressbar value. it is a number between 0 and 1
  • progressbar - (object) progressbar.
onComplete
Arguments:
  • progressbar - (object) progressbar.
Upload events:
onCreate

Fired after the upload instance has been created.

Arguments:
  • transfer - (object) file upload instance
onStart

Fired after transfer is started.

Arguments:
  • transfer - (object) file upload instance
onLoad

Fired before the file is uploaded.

Arguments:
  • options - (object)
Options:
  • element - (element) the file upload instance container.
  • file - (string) the file name.
  • size - (int) file size. if the browser supports XMLHTTPRequest file upload, this will be the actual file size, otherwise it will be 0.
  • transfer - (object) file upload instance.
onProgress

Fired while the file is uploaded.

Arguments:
  • value - (number) - the progress value is between 0 and 1
onAbort

Fired when the transfer is aborted before the file is uploaded.

Arguments:
  • options - (object)
Options:
  • file - (string) file name
  • message - (string) error message
  • transfer - (object) file upload instance.
onCancel
Options:
  • message - (string, optional) error message

Fired when the transfer is cancelled.

Arguments:
  • transfer - (object) file upload instance.
onFailure

Fired when the transfer fails.

Arguments:
  • transfer - (object) file upload instance.
onSuccess

Fired when the transfer succeed.

Arguments:
  1. infos - (object) uploaded file infos
Infos:
  • file - (string) the original file name.
  • path - (string) the encrypted file path on the server.
  • size - (int) uploaded file size.
  • transfer - (object) file upload instance
onPause

Fired when the transfer is paused.

Arguments:
  • transfer - (object) file upload instance
onResume

Fired when the transfer is resumed.

Arguments:
  • transfer - (object) file upload instance
onComplete

Fired when the transfer is complete.

Arguments:
  • transfer - (object) file upload instance
onAllComplete

Fired when all transfer are completed.

Arguments:
  • container - (string) container id

uploadManager Method: attachDragEvents


enable files to be uploaded when they are dropped on an element. this happens only if the browser supports file drag drop.

Returns:

  • (object) - uploadManager.

Arguments:

  1. el - (mixed) element
  2. options - (object) see uploadManager#upload .

uploadManager Method: detachDragEvents


remove upload events from an element.

Returns:

  • (object) - uploadManager.

Arguments:

  1. el - (mixed) element

uploadManager Method: get


return the file upload instance with the given id.

Returns:

  • (object) - file upload instance.

Arguments:

  1. id - (string) file upload instance id.

uploadManager Method: getSize


return uploaded file size for a given container.

Returns:

  • (mixed)

Arguments:

  1. container - (string) container id

return all the file upload instance of a given container.

uploadManager Method: getTransfers


return the transfer instances for a given container.

Returns:

  • (array)

Arguments:

  1. container - (string) container id

File upload instance {#uploadManager:instance}


object wrapping a file upload instance.

Implements

Options, Events. see uploadManager#upload for implemented options and events.

File upload instance Properties:


  • completed - (boolean) true if the file has been succesfully uploaded
  • filesize - (int) the uploaded file size in byte.
  • state - (int) state of the transfer of this instance. value are: 0 (not started), 1 (loading), 2 (aborted), 3 (cancelled), 4 (completed)
  • progressbar - (object) progressbar. the progressbar is created only after the file is loaded.

Example

//CSS

#dropfiles {

	border: #000;
	width: 100%;
	height: 250px;
}

//HTML
		<script src="mootools.js"></script>
		<script type="text/javascript" src="number.js"></script>
		<script type="text/javascript" src="progressbar.js"></script>
		<script type="text/javascript" src="upload.js"></script>
		
		
		<a href="#">Select a picture</a>
		<div id="dropfiles"></div>

//Javacript

window.addEvent('domready', function () {
	
	//upload options
	var options = {
					//upload container
					container: 'dropfiles',
					
					//only one file can be uploaded
					limit: 1,
					
					// uncomment the following line to enable folder upload in google chrome 22+
					// folder: true,
					
					//upload field name
					name: 'picture',
					
					//filter by file type
					filetype: 'jpg,gif,png',
					
					//where to send uploaded file
					base: '/files/upload',
					
					// dynamically add UI elements to the upload field
					onCreate: function (transfer) {
								
						//add ui elements dynamically like a textarea ?
						transfer.toElement().grab(new Element('span[text=UI element]'))
					},
					onComplete: function () {
					
						alert('I am complete')
					},
					allComplete: function () {
			
						alert('Yay! we are all complete')
					}
				}
				
	//enable drap & drop
	uploadManager.attachDragEvents('dropfiles', options);
	
	//add a new upload on click on the link right before #dropfiles
	document.getElement("#dropfiles!+a").addEvent("click", function (e) {
	
		e.stop();
		
		uploadManager.upload(options);
	})
})

Example

a simple form to upload a text file.

HTML:

<form action="" method="get">
	<a href="#">Upload a picture of you:</a>
	<div id="upload"></div>
	<input type="submit" value="submit"/>
</form>

Javascript:

var options = {

	//upload only one file
	limit: 1,
	//upload in this element
	container: 'upload',
	//allowed file type
	filetype: 'jpg,gif,png',
	//transfer aborted
	onAbort: function () {
	
		alert('Unauthorized file type, allowed file type are "' + this.options.filetype + '"')
	},
	onSuccess: function () { alert('Transfer completed succesfully!') }
};

// check files are uploaded before the form can be submitted
window.addEvent('domready', function () {

	//add click listener on the link
	document.id('upload').addEvent('click', function (e) {
	
		e.stop();
		
		//create upload field
		uploadManager.upload(options)
	}).
	//check submit form
	getParent('form').addEvent('submit', function (e) {
	
		e.stop();
		
		//transfer instances
		var transfers = uploadManager.getTransfers('upload');
		
		//user have not uploaded a file
		if(transfers.length == 0) {
		
			alert('Please select a file to upload');
			return
		}
		
		//check we have ungoing transfers
		if(transfers.some(function (instance) { return instance.state == 1 })) {
		
			alert('there are some pending queries, please wait until it completes, the try again');
			return
		}
		
		//check all transfers have completed
		if(!transfers.every(function (instance) { return instance.complete})) {
		
			alert('some tranfers may have failed. please try again');
			return
		}
		
		//all transfers have completed succesfully, submit the form
		alert('Yay!');
		
		//this.submit()			
	})
})

uploadmanager's People

Contributors

davsket avatar dmitrydvorkin avatar ma-jo avatar pfz avatar sunbox avatar tbela99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

uploadmanager's Issues

Script stops working on https

Hi there,

I have created a form which includes photo uploads using this script. The script works fine when it runs over http:// , but when the same page is accessed by https:// the photo's don't get uploaded. The process hangs after choosing the file, giving the message "Pending..."
Part of the strange behaviour: on localhost it works fine on https. It only hangs when it is online. Any ideas what might be causing it?

Thanks

Multiple upload instances

Hi Thierry,

How can I create multiple "uploadManager" instances in one page?
Something like uploadManager[] as an array would be awesome to have, so you can have different aliases in different forms.

something like var uploadManager1 = new uploadManager();
and var uploadManager2 = new uploadManager();

Is this easy to accomplish?

Drag And Drop

I am unable to get drag and drop to work using the example in the latest chrome and ie, it appears if their is no event listener being added to the page, even thought uploadManager.attachDragEvents('dropfiles', options); has been called ?

Uploads not saving

Have tried to get the demo to work, unsuccessfully.

Environment
Browser: Firefox 3.6
Server: Apache, Nginx (tried on both)
UploadManager Version: 1.1, HEAD (tried on both)

What happens:
I unpacked upload manager and tried to upload a file to the demo.
Three errors are thrown:
PHP Warning: file_put_contents(/ul/php/tmp/img0.jpg)
[function.file-put-contents]: failed to open stream: No such file or directory in /ul/php/upload.html5.php on line 17
PHP Warning: filesize()
[function.filesize]: stat failed for /ul/php/tmp/img0.jpg in /ul/php/upload.html5.php on line 19
PHP Warning: unlink(/ul/php/tmp/img0.jpg)
[function.unlink]: No such file or directory in /ul/php/upload.html5.php on line 31

Have tried integrating into my own server side upload script, same issues.
The encoding type is text/plain non enctype/form-data, which I assume is causing the issues.

demo do not work.

Hi Bela,
I'am trying to use your code and I think i have a problem with the php-part.
I copied the complete code to my server without any changing.
If I call the /demo/index.html it shows the same as like your demo. But I cant upload something. If I choose a file, the bar shows <<Pending...>> and nothing else happens. (On submit its alerts <>)
Whats wrong?
Where can I set a upload-folder?
Is there any Documentation of your php-code?
thx in advance for any help

(PS: all folder has 777)

PeriodicalExecuter.js is missing

When I run the demo from the uploadManager archive Firebug says that a PeriodicalExecuter.js is missing. It's not in the archive! Is it a legacy or needed?

Checkbox display:none

The check boxes that are used to contain the file name information appear to have a style of "display:none" however the one with the name created from options.name, loses its style specification.
if there is a good use for the checkbox then please document this, otherwise somewhere either in the javascript (looked but could not find it) or as a quirk of DOM the style is being removed.

License?

Hey,

i like to use your uploadManager for a commercial product. You did not specify a license for this project. Please specify one!

Thanks

IE not compatible

There appears to some degree of compatibility with IE by using the "IE Compatibility Mode".
Regular (non-drag/drop) uploads appear to work. Drag/drop lets you think that it is going to work but does not upload anything.
With "IE Compatibility Mode" turned off nothing works.
Also see separate issue regarding "Checkbox display:none" not working.

upload-container not removed on browser window cancel

Hi!

I noticed that the new upload-container (with the "Browse..." and "Cancel" buttons) in the drag&drop box is not removed when the browse window is closed or canceled. Is this intentional or bug?

I use uploadManager 1.4.2, tested with Firefox 11.0 on Kubuntu (Oneiric).
Same with Chromium 18.0.1025.142 (Developer Build 129054 Linux) Ubuntu 11.10

thanks
Karesz

Progress value jumping around

Hi,

I tested the Demo of your uploadManager on my own server and on localhost.
It works really great, but I have one issue:
During the upload, both the progress value and the progress bar "jump around", the value jumps for example from 1.5% to 0.7% and then to 1.3%, but values increase over time. So they are roughly correct, but I don't like it if a progress bar decreases during an action when it is supposed to increase...
I could not figure out what the reason for this strange behavior could be.
Rounding the values to integer values improved the situation a bit, but sometimes the value still jumps down a bit, and especially the progress bar still jumped around.
I am using FF19.0.2 on linux.

Thanx in advance

PS: I think I will make a German localization tomorrow.

Event(s) missing when using IFrame?

I'm trying to implement uploadManager in CodeIgniter, so I've had to do some changes in the php-files to support CI, and small changes in the "upload.js" to replace "?" with "/" in the request url's. HTML5Transfert with the "onComplete"-event works, but Transfert uploads the file, triggers its own "complete", but not my "onComplete"-event or "allComplete"-event.

Transfert's "complete" in my upload.js:

complete: function () {
    if(uploadManager.actives[container].length == 0 && uploadManager.queue[container].length == 0) {
        console.log(this);
        uploadManager.active = false;
        this.fireEvent('allComplete', container);
    }
    else if(uploadManager.enqueue) {
        uploadManager.active = false;
        uploadManager.load(container);              
    }
}

FireBug shows no "onAllComplete"-function in events for the object "Transfert". My "onComplete"/"onAllComplete" shows a form with description to the image. The form points to a php-script that finalizes the upload, then image is added to the gallery on the same page.

var options = {
    iframe: true,
    container: 'image_upload',
    cancelElement:'cancel_button',
    base: '.../upload',
    //filter file types
    filetype: 'jpg,jpeg,jpg',

    //form field name
    name: 'names[]',

    multiple: false, //enable multiple selection in file dialog
    progressbar: {

        width: 140, //fix the progressbar width, optional
        color: '#000', 
        fillColor: '#fff',
        text: 'Pending...',
        onChange: function (value, progressbar) {
            progressbar.setText('completed: ' + (100 * value).format() + '%')
        },
        onComplete: function(){//happens when using "iframe:false"
            //Make file-upload-form
            alert('onComplete');
            $('form_rest').setStyle('display','block');
            $('pre_upload').setStyle('display','none');
        },
        onAllComplete: function(){
            //Make file-upload-form
            alert('onAllComplete');
            $('form_rest').setStyle('display','block');
            $('pre_upload').setStyle('display','none');
        },
        onCancel: function(){
            //Clear the upload-file-form
            $('form_rest').setStyle('display','none');
            $('pre_upload').setStyle('display','block');
            $('image_description').innerHTML = '';
            $('image_upload').empty();
        }
    }
};

upload.js on github vs upload.js in the demo

Hi,

thanks for this great class!

I've got an issue:

if I use the upload.js from the github download package, the "[upload size: 0]" does not get updated. If I copy the upload.js from the demo, it works.

Thank you

File type authorization fails in Chrome

Chrome Version 20.0.1132.57

File type doesn't get authorized; object is always undefined for following:

//file type filter
if (options.filetype) this[addEvent]('load', function (object) {...

Further Documentation Requested

It would appear that the usage for this uploader is as follows :
"Include in an outer form that when submitted will move the files from the tmp folder to their final location."

If that is what is intended then please confirm and add to the documentation.

Also the progress bar is based on a timer which means that when the upload is quicker than the timer it looks like only a small percentage of the upload took place.

Clicking Download On form before submission Fails

So i installed upload manager and have been trying to test it when i upload a file using the sample interface there is a download link next to it, This always failed page not found error I traced it back to a function in upload helper, the below code fixed the issue for me but is probably not safe i dont understand why the regex expression fails i may have another look later

public static function safe_name($name) {
return strtolower($name);
//return strtolower(preg_replace('/[^a-z0-9,._]+/i', '-', self::str_search($name)));
}

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.