As I’ve mentioned a few times before I’ve been playing around with Adobe Flex. I finally got some more time to play with it tonight, so I got everything together to a semi-usable shape. A few things are still missing, such as moving the active uploads to the top and handling more than a total number of x queued uploads (at a certain level the progress bars will just disappear out of the Flash area, then magically appear as enough other items are finished).
I’m looking for any response on this, and if anyone want to play around with it, please go ahead. It should be fairly simple to set up. I’ve included a brief description of the arguments it accepts below. Everything is released under a slightly modified MIT-based license, where the only change is that I’ve removed the need for keeping the copyright notice in anything that’s not the source code itself. Use it for anything you’d like, and if you make something useful, I’d be happy if you would contribute at patch back to me so that I could update the library itself.
You can see the application in action at my test installation. I’ll remove this test later, and be advised that the files actually will be transferred to my webserver. I’m just going to run rm -f * anyways, but if anyone breaks in and steals your precious uploaded files, you’re the one to blame.
== ARGUMENTS == The arguments to the flash file are provided in the flashVars attribute. There are two required parameters: destinationURL The destination where all files are uploaded. redirectWhenDoneURL The URL the client is redirected to when all files have been uploaded. Remember to urlencode both values. Example: <SEE THE INSTALL FILE IN THE ARCHIVE> Optional parameters that are available is: progressIndicatorColor: "#bfbfbf" The color of the progress bar. progressIndicatorBackgroundColor: "white" The color of the empty bar before any progress has been made. progressIndicatorWidth: 300 The width of the progress bar indicator. uploadButtonText: "Click here to upload files!" The text of the button the user has to click to start uploading files. == COMPILING == To compile the SWF-file from the source code, download the Adobe Flex 3 SDK, then run mxmlc against Swoooosh/Swoooosh.mxml: mxmlc Swoooosh/Swoooosh.mxml == CONTACT == Any and all comments are welcome. See the included LICENSE file for information about usage. Short words: do whatever you want, just don't claim you wrote it without contributing. All patches are of course welcome.
As I’ve received many comments about the contents of test.php (the file that receives the post), here is the smallest version:
foreach($_FILES as $file)
file_put_contents('directory_name_to_write_files_to/' . uniqid(), file_get_contents($file['tmp_name']));
This will simply loop through all submitted files and write them to the temporary directory. As with other file uploads in PHP, you can access the original name of the file with the ‘name’ element in the $file array. DO NOT USE FILE NAME FROM ‘name’ WHEN WRITING THE FILE TO DISK. DOING THAT IS A VERY BAD IDEA, AS IT ALLOWS PEOPLE TO CREATE ANY FILE WITH ANY NAME (INCLUDING PHP-FILES WHICH CAN BE RUN IF THEY’RE AVAILABLE THROUGH THE WEB SERVER. YEP.). CAPS OFF.
Remember to make the directory you’re saving the files in WRITABLE for the process that writes the files (might be www-data or whatever user your webserver is running under). If you want to debug the response from the server regardless of what’s shown in the flash UI, use Wireshark to see the raw contents of packets and the conversions between the client and the server.