I also realize that I'm just posting code. You'll have to get the original SWFUpload and make sure all your file names and paths are correct/updated before this example code will work.
SWFUpload does not provide a way for having more than one upload object per page. This is probably fine for most cases. However, if you want to upload an image and a word document (with different file size constraints or other settings) you need to have more than one upload object on the page.
So, I've revised the SWFUpload script. I had to restructure the design a bit (SWFUpload was built as a "Static" object, I needed it to work as an "Instance" object).
The new script operates almost like the original. However, these changes make it so you can't just throw a script tag in the body and instantiate the upload object. If you try that IE will have a fit. So you need to attach some code to the window.onload event (or any event that gets executed after the page is finished loading).
Operational Notes/Change log
My installation of Internet Explorer is broken. The SWFObject flash detection does not work for me. I've updated the SWFUpload script so you can set the "flash_version" setting to 0 (zero) bypassing the version detection. I'm not sure what will happen if Flash is not installed.
I've replaced the Debug output with a "Debug Console". The old debug doesn't work now that we have to wait until the page is loaded. The Debug Console looks for a FORM tag, adds a TextArea and puts the output there. If it can't find a FORM then it creates one and adds it to the body.
I've added a setting that allows you to tell SWFUpload where to add the Flash objects. ASP.Net requires that the Flash be added outside the FORM tags.
I've added a setting that indicates where to place the A tag (link) that causes the File Dialog to open.
I've updated the default Error Handler so it writes to the "Debug Console" instead of putting up alerts.
I de-obfuscated a bunch of the SWFObject code. So, now it's easier to read, but makes for a larger file.
Here are some tips on using this thing:
- Refer to the script's init method to see all the settings and their defaults
- Any settings you don't include will automatically get the default value
- Any callbacks you don't specify won't be called
- Setting flash_version to 0 (zero) disables the flash version detection
- You can use the Debug Console for your own output, if you want
- If you don't specifiy a ui_target setting (or the target is not found) then the Upload link is not added.
- You can call up the File Dialog yourself using the callSWF() method on your SWFUpload instance objects.
- If you don't specify a flash_target setting the script adds the flash to the body (which will be outside any FORMs).
- In your events the this object won't be your SWFUpload instance object.
- SWFUpload doesn't seem to work if you are viewing the page as a local file (file://). You need to put it on a web server (http://)
- SWFUpload will probably return an error if your upload_backend is not a script file (if you submit to an html/htm file IIS will return a HTTP 405 error. Submit to a script file (php, aspx, etc).
- Make sure you upload_backend file is working normally before using it with SWFUpload. You will get IOErrors or HTTP errors.
- For ASP.Net developers you'll want to make sure your maxRequestLength and executionTimeout are large enough.
So, there you go. Again, Good Luck!