PHP5 / AJAX FTP Drag and 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.

If you want to see an online demo, just ask in the comments :)

Comments

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.

    by Derek on Jun 20, 2007 @ 2:11am

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.

    by Peter Goodman on Jun 20, 2007 @ 8:45am

Hi,

I'm interested in getting a copy of Ajax FTP program (if possible, :). Thanks in advance.

Amy

    by Amy on Jun 21, 2007 @ 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.

    by Peter Goodman on Jun 21, 2007 @ 10:26pm

Looks pretty good, i'll take a look into the code this weekend ;)

    by marcoss on Jun 28, 2007 @ 12:05am

Watch out tho! The installation instructions don't necessarily hold valid any more because I'm constantly changing parts of the framework :P

    by Peter Goodman on Jun 28, 2007 @ 8:31am

This is exactly what i am looking for. Can you post new installation instructions please?

Thank you

    by munson on Sep 30, 2007 @ 12:52pm

How does that work? Which files do I need? can you also send it to me please?

    by Ivy on Apr 1, 2008 @ 4:52am

Hey, I'm interested in having a look at your FTP application. Could you please email me the installation files?

Many thanks,

Add a Comment