PHP5 / AJAX FTP Drag and Drop Uploader
Note: I no longer support or distribute the code for the drag & drop uploader.
So over the weekend and up until today I've been having fun with the PHP5 framework that I'm working on. One particular system that I'm proud of is the layers system. As it sounds, it manages layers. For example, database abstraction currently has two layers: SQLite and MySQLi. There's nothing too interesting about that. What is interesting are my current file layers: System and FTP (planned: Amazon S3 and LDAP).
With these file layers I have made it stupidly easy to transparently transfer files from one layer to another (FTP->System, System->FTP). I was proud of these generally simple classes so I decided that I wanted to flex their muscles. I made a system to ftp uploader. I added a dash of jQuery and a stupid amount of javascript and now I have myself a drag and drop uploader!
I made a quick video of it in action. Sorry for the poor quality / ugly demo text. When I have money in my bank account, I will invest in a better screen capture program, I swear! Take a look at a short video of the FTP AJAX uploader in action here.
By the way, the total amount of PHP (in the controller) to handle all that is just over 200 lines (including comments). Here's the jist of how files are transferred:
// get the file layer fos the source files
$from_system = $this->getLayer('file', $from_layer);
// get the source files
foreach($files as $key => $file_name) {
$files[$key] = $from_system->find($file_name, FileAbstract::FILE);
}
// transfer them to the destination directory, note: write() will accept
// 3 different argument types: FileAbstract, Iterator, or a file path/name.
$this->getLayer('file', $to_layer)
->find($log["last_{$to_layer}_location"], FileAbstract::DIRECTORY)
->write(new ArrayIterator($files));
And here's how I list out files in a directory:
// get the layer
$file_system = $this->getLayer('file', $layer);
// find the directory, read the files from it, and set it
// as a template list
$response['files'] = $file_system->find($dir, FileAbstract::DIRECTORY)->read();
Pretty neat. The templates--using my own template engine based on this HTML parser--are equally sweet.
Comments
-
How does that work? Which files do I need? can you also send it to me please?
posted by Ivy on Apr 1, 2008 at 4:52am -
Hey, I'm interested in having a look at your FTP application. Could you please email me the installation files? Many thanks,
posted by James Star on Jul 8, 2008 at 11:46pm -
This is exactly what i am looking for. Can you post new installation instructions please? Thank you
posted by munson on Sep 30, 2007 at 12:52pm -
Hello Peter, me too wanna see your application =) Developing something similar, please you can send me installation files?
posted by Rodrigo on Nov 4, 2008 at 8:32am -
I have started working on a jquery script to do the same thing that i do in this script for dragging and dropping multiple objects at a time. I'll post the code on this blog when I'm done. Otherwise, if you're interested in the code, I could post a zip online.
posted by Peter Goodman on Jun 20, 2007 at 8:45am -
Watch out tho! The installation instructions don't necessarily hold valid any more because I'm constantly changing parts of the framework :P
posted by Peter Goodman on Jun 28, 2007 at 8:31am -
Looks pretty good, i'll take a look into the code this weekend ;)
posted by marcoss on Jun 28, 2007 at 12:05am -
As I just start to look into how I might do this, my first Google hit is you showing how you've just done it. Very nice.
posted by Derek on Jun 20, 2007 at 2:11am -
Hi, I'm interested in getting a copy of Ajax FTP program (if possible, :). Thanks in advance. Amy
posted by Amy on Jun 21, 2007 at 8:34pm -
Great! Okay, let me explain how to get it up and running. What you will be downloading is my php5 framework in development. The uploader is part of that! first, go download/unzip http://ioreader.com/code/iocore.zip second, put it somewhere accessible by either your own local server or online. I suggest putting the 'valkyrie' folder above the document root, where the 'wwwroot' directory is the document root. Whatever. Assuming you are up and running, go to your equivalent of: http://localhost/iocore/wwwroot/upload/install/ to install it, then go to http://localhost/iocore/wwwroot/upload/ and you should see it! To configure which FTP server it connects to, check out valkyrie/application/config.php. One problem I've been having recently is that it copies the files over but not their contents. If you get any other php errors, please tell me! You find the model layer a bit of a mess if you delve into it because it's what I've recently been working on. Also, the only database table used in the uploader is /valkyrie/application/models/log.php. The uploader, by default, uses a SQLite database.
posted by Peter Goodman on Jun 21, 2007 at 10:26pm -
We have a product called IntegralFTP, which allows you to do the sort of thing Peter's referring to (unless I've misunderstood it - sorry). You can use it to do FTP, SFTP and FTPS operations from Javascript. It's basically a Javascript class that uses an invisible Java applet to do the actual FTP/FTPS/SFTP comms. We think it's pretty cool. :-)
posted by Hans Andersen on Nov 9, 2009 at 11:34pm
You can find it at http://www.enterprisedt.com/products/integralftp/overview.html.
Comment
