Thursday, February 22, 2007

A License for my Work

The question of the license which I apply to my work has been brought to my attention in the comments on the Taskbar Shuffle post.

This post is simply to keep things "on topic" and to have a place to discuss the question.

I've elected to place my source code, my posts, and comments under the Creative Commons Attribution 2.5 License.

This license allows free use of my creative works so long as you include attribution.

Acceptable attributions are:
Any attribution should include a link to or the complete text of the appropriate Creative Commons license.

(if someone with more experience can make better suggestions please chime in)


For the most part I don't really care how my work is used. I would feel a little upset of someone copied one of my posts and then claimed it was their own creative work (unless they corrected my grammar and clarified my sentences and sent me a copy ;) ). But I just hope my rambling can save some time for someone else (p.s. I won't turn away any gratitude (especially the kind accepted at the local computer shop)).

However, some of my work (e.g. the Natural Sort Algorithm in C#) is derived from the work of others and I would appreciate it if a link back to my post was made so it is clear that the real work originated from some other really smart people.

Also be aware that some works (e.g. the Natural Sort Algorithm and SWFUpload) already fall under other licenses. I'm not always good about following up on those. If you have a concern regarding derivative works please let me know.

Thursday, February 15, 2007

Taskbar Shuffle

The Windows Taskbar has always annoyed me. I always thought Windows 3.1 had it right. (Don't get me started on helping Grandma find the documents she saved to the desktop rather than My Documents)

My biggest issues with the Taskbar are:
  • I like to have my "tasks" in a particular order. I have, in fact, closed all my other programs and re-opened them just to return them to the proper order on the Taskbar.
  • I like related tasks to be grouped together. Especially multiple windows from the same application.
  • If I accidentally close a program I don't want it to re-open at the end of the task list. I want it to be where it was. Outlook always goes first, if it's suddenly last it takes me ages to find it.
So, Microsoft finally made some improvements in Windows XP with their Task Grouping settings but it still doesn't really cut it.

You can only imagine how happy I was when I found Taskbar Shuffle. It does one wonderful thing. It lets me click and drag the tasks allowing me to re-order them any way I want! So what if it did a funny inverted colors thing.

The 2.0 version was recently released and things are only better. It looks a lot better for one thing. And it has a new grouping features that group new windows from the same application (I mean you Internet Explorer) together. This isn't the "collapse into a single task" grouping. It's just keeping the tasks next to one another.

So, I highly highly recommend this great little utility!

(no, I'm not advertising or have any monetary interest in Taskbar Shuffle. A great app just deserves high praise!)

Wednesday, February 14, 2007

SWFUpload - The Back End

I've received some more feedback and I've finished my first implementation of SWFUpload R3 in one of my own websites (which is on an Intranet so, unfortunately, I can't show it off).


Issues of note:
  • My code uses document.getElementById to access the Flash movie. I received a report that this doesn't work in Firefox on OS X. document.embeds was recommended as an alternative. The original SWFUpload used a similar method. If you use document.embeds make sure you test in IE on Windows. IE used the "Object" tag rather than the "Embed" tag.
  • Using SWFUpload in FireFox behind a Proxy that requires HTTP Authentication does not work for me. It does prompt for a username/password but will not accept it. In fact Flash locks up Firefox and you have to retype your blog posts from scratch.
  • You can still force the IE Forms issue from the original SWFUpload if you insist on loading the flash inside a form without using the window.onload event. Don't do it, that was the whole point of SWFUpload R3.
  • In my testing I found that Flash in Firefox (2.0) does not send the Firefox cookies to the upload_backend file. It seems to send the IE cookies instead. This seems like a security issue, but maybe it's just happening to me. I should do some more testing. However, in many environments if your cookies aren't sent then you will have lots of problems with user authentication and sessions.

Build the Back-End

Receiving and processing the uploaded file is a bit tricky. At least it was for me since I had to work around the FireFox Flash Cookie issue I experienced (and explained above).

Here are some main points to remember:
  • You may not be able to rely on the cookies that flash sends (for Sessions and authentication)
  • The only way to notify SWFUpload of an error in the upload is to return an appropriate HTTP status code. You will probably want to send a HTTP 500 status and then handle the error SWFUpload sends to the page.
  • You can send values to the upload backend using the query string. E.g. upload_backend : "upload.php?fileid=ABCDEFG0123456789&bob=john".
  • Each upload is sent via a separate request. You don't have to worry about handling multiple uploads. You only have to handle the one upload in the Filedata post value.
SWF Upload sends the following data to the backend:
  • Filedata: This is the name of the file upload and contains all the data about the file.
  • Filename: This contains the name of the file. It is kind of redundant.
  • Upload: In my testing this always contains the string "Submit Query". I have no idea what it is for.

Code Samples:

ASP.Net Sample:
try
{
Request.Files["Filedata"].SaveAs("/path/and/file/name.ext");
}
catch
{
Response.Status = 500;
}



ASP Sample:
if (Request.Upload.Files.Count > 0) then
if (Not Request.Upload.Files("uploadedfile").SaveAs(Server.MapPath(FileName), True)) then
Response.Status = 500
end if
end if



ColdFusion sample:
<cffile action="upload" destination="/path/and/file/name.ext" filefield="form.filedata">



PHP Sample:
if (!move_uploaded_file($_FILES['Filedata']['tmp_name'], "/path/and/file/name.ext")) {
header("HTTP/1.0 500 Internal Server Error");
}


I have not tested these samples. They are built based on sample code from around the web. Feel free to suggest better samples if you've got them.