Other versions:

FancyUpload - Swiff meets Ajax (v2.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”

Creating a nice looking upload queue, including animated progress bars.

The Action Happens Here

File Upload

Selected your photo to upload.
This form is just an example fallback for the unobtrusive behaviour of FancyUpload.

Browse Files | Browse Only Images | Clear List | Upload

Overall progress
File Progress
    This showcase is outdated, please visit the new showcase for FancyUpload 3.0. Documentation & Download for FancyUpload 3.0 here. 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.

    Check the Firebug console for event debugging logs. Filesize is limited to 2Mb (client- and serverside).

    JavaScript & MooTools

    window.addEvent('load', function() {
     
    	var swiffy = new FancyUpload2($('demo-status'), $('demo-list'), {
    		'url': $('form-demo').action,
    		'fieldName': 'photoupload',
    		'path': '../../source/Swiff.Uploader.swf',
    		'onLoad': function() {
    			$('demo-status').removeClass('hide');
    			$('demo-fallback').destroy();
    		}
    	});
     
    	/**
    	 * Various interactions
    	 */
     
    	$('demo-browse-all').addEvent('click', function() {
    		swiffy.browse();
    		return false;
    	});
     
    	$('demo-browse-images').addEvent('click', function() {
    		swiffy.browse({'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'});
    		return false;
    	});
     
    	$('demo-clear').addEvent('click', function() {
    		swiffy.removeFile();
    		return false;
    	});
     
    	$('demo-upload').addEvent('click', function() {
    		swiffy.upload();
    		return false;
    	});
     
    });

    XHTML Markup

    <form action="/project/fancyupload/2-0/showcase/photoqueue/script.php" method="post" enctype="multipart/form-data" id="form-demo">
    	<fieldset id="demo-fallback">
    		<legend>File Upload</legend>
    		<p>
    			Selected your photo to upload.<br />
    			<strong>This form is just an example fallback for the unobtrusive behaviour of FancyUpload.</strong>
    		</p>
    		<label for="demo-photoupload">
    			Upload Photos:
    			<input type="file" name="photoupload" id="demo-photoupload" />
    		</label>
    	</fieldset>
     
    	<div id="demo-status" class="hide">
    		<p>
    			<a href="#" id="demo-browse-all">Browse Files</a> |
    			<a href="#" id="demo-browse-images">Browse Only Images</a> |
    			<a href="#" id="demo-clear">Clear List</a> |
    			<a href="#" id="demo-upload">Upload</a>
    		</p>
    		<div>
    			<strong class="overall-title">Overall progress</strong><br />
    			<img src="../../assets/progress-bar/bar.gif" class="progress overall-progress" />
    		</div>
    		<div>
    			<strong class="current-title">File Progress</strong><br />
    			<img src="../../assets/progress-bar/bar.gif" class="progress current-progress" />
    		</div>
    		<div class="current-text"></div>
    	</div>
     
    	<ul id="demo-list"></ul>
     
    </form>

    PHP Script

    <?php
     
    $result = array();
     
    if (isset($_FILES['photoupload']) )
    {
    	$file = $_FILES['photoupload']['tmp_name'];
    	$error = false;
    	$size = false;
     
    	if (!is_uploaded_file($file) || ($_FILES['photoupload']['size'] > 2 * 1024 * 1024) )
    	{
    		$error = 'Please upload only files smaller than 2Mb!';
    	}
    	if (!$error && !($size = @getimagesize($file) ) )
    	{
    		$error = 'Please upload only images, no other files are supported.';
    	}
    	if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )
    	{
    		$error = 'Please upload only images of type JPEG.';
    	}
    	if (!$error && ($size[0] < 25) || ($size[1] < 25))
    	{
    		$error = 'Please upload an image bigger than 25px.';
    	}
     
    	$addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);
     
    	$log = fopen('script.log', 'a');
    	fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . preg_replace('/^[^.]+/', '***', $addr) . ": {$_FILES['photoupload']['name']} - {$_FILES['photoupload']['size']} byte\n" );
    	fclose($log);
     
    	if ($error)
    	{
    		$result['result'] = 'failed';
    		$result['error'] = $error;
    	}
    	else
    	{
    		$result['result'] = 'success';
    		$result['size'] = "Uploaded an image ({$size['mime']}) with  {$size[0]}px/{$size[1]}px.";
    	}
     
    }
    else
    {
    	$result['result'] = 'error';
    	$result['error'] = 'Missing file or internal error!';
    }
     
    if (!headers_sent() )
    {
    	header('Content-type: application/json');
    }
     
    echo json_encode($result);
     
    ?>

    CSS Stylesheet

    #demo-status
    {
    	background-color:		#F9F7ED;
    	padding:				10px 15px;
    	width:					420px;
    }
     
    #demo-status .progress
    {
    	background:				white url(../../assets/progress-bar/progress.gif) no-repeat;
    	background-position:	+50% 0;
    	margin-right:			0.5em;
    }
     
    #demo-status .progress-text
    {
    	font-size:				0.9em;
    	font-weight:			bold;
    }
     
    #demo-list
    {
    	list-style:				none;
    	width:					450px;
    	margin:					0;
    }
     
    #demo-list li.file
    {
    	border-bottom:			1px solid #eee;
    	background:				url(../../assets/file.png) no-repeat 4px 4px;
    }
    #demo-list li.file.file-uploading
    {
    	background-image:		url(../../assets/uploading.png);
    	background-color:		#D9DDE9;
    }
    #demo-list li.file.file-success
    {
    	background-image:		url(../../assets/success.png);
    }
    #demo-list li.file.file-failed
    {
    	background-image:		url(../../assets/failed.png);
    }
     
    #demo-list li.file .file-name
    {
    	font-size:				1.2em;
    	margin-left:			44px;
    	display:				block;
    	clear:					left;
    	line-height:			40px;
    	height:					40px;
    	font-weight:			bold;
    }
    #demo-list li.file .file-size
    {
    	font-size:				0.9em;
    	line-height:			18px;
    	float:					right;
    	margin-top:				2px;
    	margin-right:			6px;
    }
    #demo-list li.file .file-info
    {
    	display:				block;
    	margin-left:			44px;
    	font-size:				0.9em;
    	line-height:			20px;
    	clear
    }
    #demo-list li.file .file-remove
    {
    	clear:					right;
    	float:					right;
    	line-height:			18px;
    	margin-right:			6px;
    }

    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 (2121 Posts: )

    discussion by DISQUS 1231 Comments

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

    Sort:
    Comments 1221 – 1231 of 1231:
    • reply
      Avatar
      jojo
      said 2 years ago (1 Point)
      I see your message "Use options: data (defined in Swiff.Uploader) or return {data: …} from onBeforeOpen to set POST data" but i do not understund what i have to return...

      thanks
    • reply
      Avatar
      jojo
      said 2 years ago (1 Point)
      hello,

      Who can explain me how to send POST data while uploading ? Thanks !!!!
    • reply
      Avatar
      jyuza 1 Point
      said 2 years ago (1 Point)
      First of all, I would like to express my gratitude to all of those who helped each other on the previous version of FancyUpload. Thanks to you guys, specially Digitarald for his tremendous programming skills and for all the time he spends, helping people, like me, with no real knowledge in Javascript.

      I was using the previous version of FancyUpload and I am trying to use the brand new one. Right now I got it work, but I had to copy the Mootools.js in the example to make it work because the Mootools version don't work. That was the only problem I had (maybe it will help, who knows).

      And here comes the question. Like someone who posted in the comments, I am trying to post Data along with the Files I upload. My problem is that I have a <select> items, and I would like to send Image with the Id I would select in the list of items. How can I proceed ? Thank you very much my friends, J.</select>
    • reply
      Avatar
      Bodom78 5 Points
      said 2 years ago (1 Point)
      Have not tried it out personally but playing with the demo it worked great for me in FF 2.0.0.14 and IE6/7.

      This is a really nice integration of JavaScript and Flash, great work.
    • reply
      Avatar
      said 2 years ago (1 Point)
      How I can send POST data with the fileupload?
      I user mod_rewrite for my website, so I can't use GET...

      I can't find a documentation...

      Bist du eigentlich ein Deutscher? Im alten Code waren deutsche Kommentare xD
    • reply
      Avatar
      digitarald Site Owner
      replied 2 years ago (1 Point)
      Use options: data (defined in Swiff.Uploader) or return {data: ...} from onBeforeOpen to set POST data for a single file. I'll add documentation for that later when the API is stable. The .de in the domain is not just camouflage ;)
    • reply
      Avatar
      Jay
      said 2 years ago (1 Point)
      Harald, I'm having an issue with using callbacks, namely the OnAllComplete callback. I've tried setting passing a "callBacks" object with the onAllComplete callback defined as a function, but that causes something to break (without an error), as the uploader never actually initializes. I also tried passing an onAllComplete to the constructor like you're using onLoad, but that isn't recognized (and nothing within it is used). Any brief examples for using the other callbacks?
    • reply
      Avatar
      digitarald Site Owner
      replied 2 years ago (1 Point)
      Can you paste some more code here, so I can make sure that I understand what you are describing and what code u are using.
    • reply
      Avatar
      digitarald Site Owner
      said 2 years ago (1 Point)
      Use the option queued for that and all uploads start at one time. But uploading queued is better for the server health and faster because the connection is not shared. Usually you also resize images or do other resource-eating calculations. Also the client-server connections are limited, to 3-4 connections. Of course simultaneous uploading looks cool, but confusing for the normal user.
    • reply
      Avatar
      Piyush
      said 2 years ago (1 Point)
      This is good. Just an idea can we use Ajax to open multiple http connections and upload the files faster and simultaneously. Please post your comments on this Pros/ Cons.
    • reply
      Avatar
      Marek
      replied 1 year ago (1 Point)
      I have a problem with the uploader on Mac (both Firefox and Safari). On my site after I try to uplaod it the over progress goes to 100% straight away and each file has an error in status line: ioError #2038 and when I tested the one on this site I got another error: loading stops on 98% and the status says: httpStatus 301. ANY IDEAS?? :-)
    Comments 1221 – 1231 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.

    Developer Resources & Tools