jQuery Uploadify IE7 onComplete Workaround

Despite the fact that Uploadify seems to advertise that it works in all major browsers, the onComplete callback function is never called in Internet Explorer 7. So uploads get to 100% and then hang.

RonnieSan the author of Uploadify is looking into the issue, but until a fix comes out, here’s a workaround.

The basic idea is to use PHP’s uniqid() function to generate our new file name and send the new file name along with the uploaded file to rename it and then store the name in the local form so we can mess with it later.

So we’ll make a hidden form value with the generated file name (flnm_gen). We’ll also need one for the file name with the file extension (flnm) and one for the original file name (flnm_old) which will be filled in later with Javascript:

<input name="flnm_gen" type="hidden" value="<?php echo uniqid(); ?>" />
<input name="flnm" type="hidden" value="" />
<input name="flnm_old" type="hidden" value="" />

Then, we’ll use jQuery to detect IE7:

var is_ie7 = false;

$(document).ready(function() {
	is_ie7 = ($.browser.msie && $.browser.version.substr(0,1) == '7');
});

The following code is set up for a single file upload.

We want to disable auto-start so we can invoke the upload after some processing with auto:false.

We’ll then harness the options from onSelect to get the information about the file they are uploading and use uploadifySettings to add the new file info to the POST data sent with the file. Then we’ll start the upload from that function.

The Complete Solution

$("#fileUpload").uploadify({
	uploader: '/uploadify/uploadify.swf',
	script: '/upload/',
	folder:'uploads',
	fileDataName:'my_file',
	auto:false,
	onSelect:function(event,ID,fileObj) {
		// Store the original name
		$("input[name=flnm_old]").val(fileObj.name);

		// Get the generated value
		var new_name = $("input[name=flnm_gen]").val();

		// Get the file name extension
		var name_parts = fileObj.name.split('.');

		// Add the file extension to the generated name
		if( name_parts.length > 0 ) {
			var i = name_parts.length - 1;
			new_name = new_name + '.' + name_parts[i];
			$("input[name=flnm]").val(new_name);
		}

		// Send the new name with the file upload
		$("#fileUpload").uploadifySettings('scriptData',{'flnm':new_name});

		// Auto-start the upload
		$("#fileUpload").uploadifyUpload();
	},
	onOpen:function(event,ID,fileObj) {
		// Upload has begun
	},
	onProgress:function(e,q,f,data) {
		// Progress bar update goes here //

		// Force IE7 to "complete"
		if( is_ie7 === true && data.percentage == '100' ) {
			IE7Complete();
		}
		return false;
	},
	onComplete:function(e,q,f,res) {
		// File done uploading for all non-IE7 browsers
	}
});

// IE7's "onComplete" workaround
function IE7Complete() {
	// Video done uploading for IE7
}

Once you get the file and post data on the server side of things you can name the file like so (assuming you’re using PHP):

if( count($_FILES) > 0 )
{
	// Start a JSON response
	$response = array( 'status' => 'UNKNOWN' );

	// Path to upload directory
	$temp_loc = '/path/to/dir';

	if( !empty($_FILES['my_file']['tmp_name']) )
	{
		$temp_file = $_FILES['my_file']['tmp_name'];

		// Did they give us a "new name"?
		if( array_key_exists('flnm', $_POST) && !empty($_POST['flnm']) )
		{
			$new_name = stripslashes($_POST['flnm']);
		}
		else
		{
			// Make a new name for this file
			$pieces = explode('.', $_FILES['my_file']['name']);
			$ext = array_pop($pieces);

			$new_name = uniqid() . '.' . $ext;
		}

		$target_file =  $temp_loc . '/' . $new_name;

		// JSON response
		$response['status'] = 'OK';
		$response['old_name'] = $_FILES['my_file']['name'];
		$response['new_name'] = $new_name;

		move_uploaded_file($temp_file,$target_file);
	}
	elseif( $_FILES['my_file']['error'] > 0 )
	{
		// JSON response
		$response['status'] = 'ERROR';
		$response['message'] = 'Error uploading file.';
	}

	// Encode a JSON response
	echo json_encode($response);
	exit();
}

Good luck working with Internet Horror – Oops, I mean Internet Explorer.

0
IPv6

Internet Growth Halted – IP Address Have Depleted

On February 3rd of this year (2011) the IANA handed out the last available block of IPv4 addresses.

The free pool of available IPv4 addresses is now fully depleted. (NRO)

Once the remaining available IP addresses have been allocated (projected to be towards the end of 2011), there will be no more new IP address available on the web. That means we’ve literally run out of the 4.3 million possible IP addresses.

Internet growth has officially been “capped”. It can no longer grow in its current IPv4 skin.

IPv6 Saves The Day… Sort Of

But what about the saving grace of IPv6? A new IP address structure that allows for a bazillion (more precisely 340 undecillion) IP addresses. Hasn’t ARIN been allocating IPv6 addresses since 1999? Shouldn’t we be running on it by now? The answer is “yes” and “yes”.

But the problem is that a very small percentage (we’re talking single-digets here) of internet users are IPv6 ready. You can test your own connection for IPv6 compatibility.

IPv4 vs IPv6

Comparative Analysis of IPv4 & IPv6

Image credit: Brajeshwar

And it’s not the individual’s fault – most users are running software that works on IPv6, but their ISP is the bottle-neck. And the hosting companies that run the world’s websites are the bottle-neck. And the major corporations and universities with large networks are the bottle-neck.

Very few ISP’s, hosts, and networks around the world have upgraded to fully support IPv6.

World IPv6 Day – June 8th, 2011

In order to promote awareness of the IP address crisis, World IPv6 Day has been set for June 8th, 2011 as a “24 hour test day” for IPv6. Some of the big boys like Google and Facebook are going to celebrate World IPv6 Day by offering their services through both IPv6 and IPv4 simultaneously.

Media Temple Rumors Of IPv6 Support

I host all my sites on a Media Temple (dv) 4.0 plan. (mt) is no “ma & pap” hosting company – they are one of the largest hosting companies in the world. So surely they have support for IPv6 by now, right? Nope.

In March (mt) enabled the “AAAA” record (or quad-A record) to their DNS manager which is needed to add IPv6 addresses. That’s great, but I need a block of IP addresses to assign these quad-A records to.

I couldn’t find anywhere on the (mt) site where I could purchase a block of IPv6 addresses – in fact there is hardly any mention of IPv6 at all! So I sent a support ticket asking how one could obtain a block of IPv6 addresses and this is the response I got:

Currently IPv6 address space is not available from (mt) Media Temple. However, I can tell you we are finalizing efforts to provide this service to our customers. At this time, we have no ETA on public availability. I would suggest monitoring our weblog, as it will likely be announced there, as soon as they are available.

I responded with a message asking about the possibility of IPv6 being ready by June 8th for World IPv6 Day and they responded:

Unfortunately, I couldn’t even make an educated guess at this point. I know it is a primary goal for our engineer team for this second quarter of 2011. As for its chances of roll-out by June 8th, I’d say [they are] good. However no guarantee.

It sounds like Media Temple will be ready for IPv6 within a few months. So I will soon be able to offer my sites on both IPv4 and IPv6! And hopefully in time for World IPv6 Day!

Be A Part Of The Solution

If you run one or more websites, make them IPv6 compatible ASAP. All you have to do is get a block of IPv6 addresses and add an “AAAA” record to your DNS and configure your server. That is, of course, if your host supports IPv6. But if not, bug them with support tickets until they do. And while you’re at it – bug your local ISP too.

My local ISP back in KY didn’t respond in such a promising way when I asked them about IPv6 support:

At this time we do not support IPv6 addressing but we are always testing and planning for the future.

That was the entire message.

Is It Too Late?

But what bugs me is, why has everyone waited until now? I mean, we’ve known that we were going to run out of IPv4 addresses a really long time ago. So way wait until we’ve run out and it has become a crisis?

Perhaps this has a lot more to do with global human psychology than lazy IT guys. Perhaps the warning signs related to the impending collapse of capitalism will also be ignored until it’s an life-or-death crisis… let’s just hope we’re more prepared for that one.

 

Featured image credit: taranfx

0