Other versions:

FancyUpload - Swiff meets Ajax (v1.0)

Project FancyUpload - Swiff meets Ajax Showcase Swiff meets Ajax for powerful and elegant uploads. FancyUpload is a file-input replacement which features an unobtrusive, multiple-file selection menu and queued upload with an animated progress bar. It is easy to setup, is server independent, completely styleable via CSS and XHTML and uses MooTools to work in all modern browsers.

Showcases:

Showcase “Queued Photo Uploader”

The known example, queued upload for photos.

The Action Happens Here

Select Files

Selected photos will be queued for upload, select all your files and start upload the upload.

Upload Queue
Check the selected files and start uploading.

Get the new FancyUpload 3.0! 3.0 is the current release (more stable, more showcases, more documentation) and it is compatible with 2.0 and 2.1 (Old versions are not maintained anymore!).

What happens?

Check the automated log file after upload. The PHP script does not save the files but logs every request.

JavaScript & MooTools

window.addEvent('load', function() {
	/**
	 * We take the first input with this class we can find ...
	 */
	var input = $('demo-filedata');
 
	/**
	 * Simple and easy
	 *
	 * swf: the path to the swf
	 * container: the object is embedded in this container (default: document.body)
	 *
	 * NOTE: container is only used for the first uploader u create, all others depend
	 * on the same swf in that container, so the container option for the other uploaders
	 * will be ignored.
	 *
	 */
	var upload = new FancyUpload(input, {
		swf:  '/project/fancyupload/1-0/source/Swiff.Uploader.swf',
		queueList: 'demo-queue'
	});
 
	/**
	 * We create the clear-queue link on-demand, since we don't know if the user has flash/javascript.
	 *
	 * You can also create the complete xhtml structure thats needed for the queue here, to be sure
	 * that its only in the document when the user has flash enabled.
	 */
	$('demo-status').adopt(new Element('a', {
		'href': '#',
		'events': {
			'click': (function(e) {
				e.stop();
				upload.clearList(false);
			}).bindWithEvent()
		}
	}).setHTML('Clear Completed'));
 
});

XHTML Markup

<form action="/project/fancyupload/1-0/showcase/photoqueue/script.php" method="post" enctype="multipart/form-data" id="form-demo">
	<fieldset>
		<legend>Select Files</legend>
		<p>
			Selected photos will be queued for upload, select all your files and start upload the upload.
		</p>
		<label for="demo-filedata">
			Upload Photos:
			<input type="file" name="Filedata" id="demo-filedata" />
		</label>
	</fieldset>
	<fieldset>
		<legend>Upload Queue</legend>
		<div id="demo-status">
			Check the selected files and start uploading.
		</div>
		<ul class="fancyupload-queue" id="demo-queue">
			<li style="display: none" />
		</ul>
		<p>
			<input type="submit" id="simple-submit" value="Start Upload"/>
		</p>
	</fieldset>
</form>

PHP Script

<?php
 
if (isset($_FILES['Filedata']) )
{
	$file = $_FILES['Filedata']['tmp_name'];
	$error = false;
 
	/**
	 * THESE ERROR CHECKS ARE JUST EXAMPLES HOW TO USE THE REPONSE HEADERS
	 * TO SEND THE STATUS OF THE UPLOAD, change them!
	 *
	 * If you don't change this example-file and ask me later why your
	 * uploader can't upload other files than images I'll not answer! Thank you!
	 */
 
	if (!is_uploaded_file($file) || ($_FILES['Filedata']['size'] > 2 * 1024 * 1024) ) // Example Validation: Need file < 2Mb
	{
		$error = '400 Bad Request';
	}
	if (!$error && !($size = @getimagesize($file))) // Example Validation: Needs an image
	{
		$error = '409 Conflict';
	}
	if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) ) // Example Validation: Needs a jpeg
	{
		$error = '415 Unsupported Media Type';
	}
	if (!$error && ($size[0] < 25) || ($size[1] < 25)) // Example Validation: Needs dimensions > 25px
	{
		$error = '417 Expectation Failed';
	}
 
	/**
	 * This simply writes a log entry
	 */
	$addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);
 
	$log = fopen('script.log', 'a');
	fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . preg_replace('/^[^.]+/', '***', $addr) . ": {$_FILES['Filedata']['name']} - {$_FILES['Filedata']['size']} byte\n" );
	fclose($log);
 
	if ($error)
	{
		/**
		 * ERROR DURING UPLOAD, one of the validators failed
		 *
		 * see FancyUpload.js - onError for header handling
		 */
		header('HTTP/1.0 ' . $error);
 
		/**
		 * Abort execution and output something.
		 *
		 * FLASH NEEDS A CONTENT IN THE RESPONSE OR WILL IGNORE IT
		 */
		die('Error ' . $error);
	}
 
	/**
	 * UPLOAD SUCCESSFULL AND VALID
	 *
	 * Use move_uploaded_file here to save the uploaded file in your directory like:
	 *
	 * move_uploaded_file($file, '/user_uploads/');
	 */
 
	die('Upload Successfull');
}
 
?>

CSS Stylesheet

/**
 * Only for the structure
 */

This example and the accompanying sources/assets are © 2008-2009 by Harald Kirschner and available under The MIT License. For debugging and profiling the scripts and their markup download Firefox and use addons like Firebug and Web Developer Toolbar.

Share it: Stumble it!Digg This!del.icio.us (2099 Posts: )

discussion by DISQUS 1231 Comments

Please use the support forums for discussing the project, asking questions or posting bug-fixes!

Sort:
Comments 1 – 20 of 1231:
  • reply
    Avatar
    philmeaux 1 Point
    said 6 months ago (1 Point)
    i am not great with the javascript, but fairly dangerous with most else. i am working your fancy uploader into my site where it renames and moves the files, when they "Remove" I need to destroy those files and make other changes to data rows. I know it calls a function called "onFileRemove" but I am not sure where it fires off identifying data to and how to fire off php with that click of the "Remove" link. Can you give me some help? Thanks, am intermediate, been working to integrate this for a day now LOL.
  • reply
    Avatar
    Ian
    said 6 months ago (1 Point)
    hey. The stop() method doesn't (seem to) work. I've got a "cancel" link that should abort uploads in progress... so I call uploader.stop()

    nothing stops, the thing just keeps on uploading.

    how do I get it to work?
  • reply
    Avatar
    Rana Ssalim
    said 6 months ago (1 Point)
    in fancy upload how can i adjust file limit size ?
    please any body know tell me.
    when i upload a file and file size is greater than file limit size then show a error message before uploading.?
  • reply
    Avatar
    reffer 1 Point
    said 6 months ago (1 Point)
    Great job! I suggest separate the wonderfull class of upload from the layout objects, giving the data separated like file_name, file_size insted of writing it to a element formated and remove references to Fx.ProgressBar from the class, some people would like a simple html progressbar. It can make easy integrate in other systems. and progress can be show in diferent ways. Thanks!!!
  • reply
    Avatar
    digitarald Site Owner
    replied 6 months ago (1 Point)
    If you use only Swiff.Uploaderyou'll get a vanilla upoader without any layout.
  • reply
    Avatar
    dude
    said 6 months ago (1 Point)
    you've gone mad with the indenting!

    thanks for the code, though, hopefully i can find the source to reformat it :P
  • reply
    Avatar
    said 6 months ago (1 Point)
    Thank you for your great work, it works fine for me :-)
  • reply
    Avatar
    said 7 months ago (1 Point)
    Seems a redundant idea. Whats the point using flash. Just use dynamic iframes, watch folders and polling ajax to do multiple uploads.
  • reply
    Avatar
    digitarald Site Owner
    replied 7 months ago (1 Point)
    one more: iframes seem to be reduntant since html5 offers multi-upload
    inputs.
    iframes don't offer upload progress *and* multiple-upload dialogs. 2:0,
    flash wins.
  • reply
    Avatar
    replied 6 months ago (1 Point)
    You dynamically create an iframe to handle each individual upload. Then poll a server side script that watches the temporary file size grow. When the file is moved from the temporary folder you know its completed. By using this method you can see the progress of multiple files WITHOUT the use of flash.

    The reason this is crucial in a lot of web based applications is that large organizations will not install Flash.

    Flash only wins if available. But multi-upload is possible without it... that's all.
  • reply
    Avatar
    digitarald Site Owner
    replied 7 months ago (1 Point)
    one more: iframes seem to be reduntant since html5 offers multi-upload
    inputs.
    iframes don't offer upload progress *and* multiple-upload dialogs. 2:0,
    flash wins.
  • reply
    Avatar
    said 7 months ago (1 Point)
    Very Very nice Job !
  • reply
    Avatar
    phoenixsnake 1 Point
    said 7 months ago (1 Point)
    Thanks for the great wok in version 3
  • reply
    Avatar
    said 7 months ago (1 Point)
    Thanks for the great project. I've been wondering if it is possible to resize an image in flash *before* uploading it with this script. This is especially important for systems like appengine that have a file size limitation for image processing (1 meg currently).
  • reply
    Avatar
    Nico
    said 7 months ago (1 Point)
    Hello, I tried out setting up the attach a file example locally in a rails application, however the flash file doesn't get loaded. The params to the uploader seem okay. Any help on this?
    (I tried asking this in the forum, but got an error logging in, there seems something broken).
  • reply
    Avatar
    Nico
    replied 7 months ago (1 Point)
    Got it working!
  • reply
    Avatar
    said 7 months ago (1 Point)
    Great Work, thanks for sharing.
  • reply
    Avatar
    said 7 months ago (1 Point)
    Thanks so much for FancyUpload. I can't imagine any new site without it :-)
  • reply
    Avatar
    x
    said 7 months ago (1 Point)
    i hate people who show you cool stuff but then refuse to provide working examples.
    Really, why even bother?

    Most people on the panet do not know how this works of how to code - just provide the damn files.
  • reply
    Avatar
    dave
    replied 7 months ago (1 Point)
    There are working examples, there are links to the code, can you not read & if you don't know how to code then STFU and leave this sort of thing to people who can... idiot
Comments 1 – 20 of 1231:

Post your comment

Please use the support forums for discussing the project, asking questions or posting bug-fixes!


Internet Consultant & Contractor

I'm available to combine forces with you and your team to find the most simple, elegant and convenient web solutions . I await your call.

If you just like my work and want to say Thank You, donate via PayPal or Amazon Wish List.

Feed Subscribe Feeds

Developer Resources & Tools

Web Design Agency on Mallorca d/vision