FTP delete a folder using PHP

Had to do this for a project recently. If you’ve any experience with FTP you’ll know it’s not the most efficient of protocols. If you want to make changes to a file or folder you have to deal with each file individually.

In the case of removing a folder, you have to first make sure that it’s empty and in order to do that you have to loop through each file and delete each one in turn.

Wanted to keep note of it somewhere and figured here was as good of a place as any!


function removeFolder($ftpConnection, $path)
{
static $log = "";
$contents = ftp_nlist($ftpConnection, $path);
if(!$contents)
{
// Nothing in the folder
ftp_rmdir($path);
$log .= "Removed {$path}";
} else {
// Loop through each of the files
foreach($contents as $currentFile)
{
if($currentFile != "." && $currentFile != "..")
{
// Assuming it's a folder and there's no dot in the name
if (strpos($currentFile, '.') === false)
{
// It's a folder, so call itself
removeFolder($ftpConnection, $path."/".$currentFile);
// Once all files are gone delete the folder
ftp_rmdir($ftpConnection, $path."/".$currentFile);
} else {
// If it's a file delete it
ftp_delete($ftpConnection, $path."/".$currentFile);
}
$log .= "Removed {$path}/{$currentFile}\n";
}
}
ftp_rmdir($path);
}
return $log;
}

Battleships

Managed to finish my Battleships game and get the majority of the features completed. I left it quite late as I was busy with other work so as a result the graphics were somewhat neglected. I may not have come up with the most efficient way of coding it, but it got the job done. Included everything bar networking; doesn’t tickle my fancy just yet.

Digital Tattoo

With this task, I wanted to keep it relatively simple and concentrate on making it look like an actual tattoo. Whereas other have filled the entire area with text, I chose to include just a few words.

It’s definitely not the best photoshopped tattoo but it’s not too bad considering the brief and the time in which I did it.

 

Blog Review

Since starting this module, we’ve covered topics I’d expected but a lot more came as a surprise. In the first week we were asked to explore the idea of being a “cyborg”, exploring the definition to a point I hadn’t considered before. We thought about the extent that we would consider different technologies to be part of our lives. Whether we would think of them as a cognitive or a physical prosthesis. I found this a little strange at first, but it was only a taster of things to come.

In a way this module’s pushed me out of my comfort zone a bit and forced me to explore ideas and movements that I wouldn’t have considered before. For example, one that really made me feel uncomfortable was the art intervention. Our group decided to place stickers around town spreading the idea of being watched constantly by CCTV. It wasn’t really a subject I was passionate about, and though I’m quite outgoing normally, the idea of expressing this in public made me feel uneasy.

In all, we’ve covered some really interesting topics and it’s helped further my insight into the world of digital art. When I (and no doubt others) signed up, I’d assumed digital art referred to the digital creation of art. This is covered but it’s much more about trying to inspire us and find an area we want to expand in.

Monk abuse

Stumbled across this nice little story whilst researching the electrical telegraph:

“Jean-Antoine Nollet, the Abbot of the Grand Convent of the Carthusians in Paris decided to test his theory that electricity traveled far and fast. He did the natural thing on a fine spring day in 1746, sending 200 of his monks out in a line 1 mile long. Between each pair of monks was a 25-foot iron wire.

Once the reverend fathers were properly aligned, Nollet hooked up a battery to the end of the line and noted with satisfaction that all the monks started swearing, contorting, or otherwise reacting simultaneously to the shock.

A successful experiment: an electrical signal can travel a mile and it does so quickly. Of course, this is the kind of experiment you can only run once as your monks may prove less-than-cooperative the second time around. So, in another demonstration he discharged a Leyden jar in front of King Louis XV at Versailles by sending current through a chain of 180 Royal Guards. The King was both impressed and amused as the soldiers all jumped simultaneously when the circuit was completed. “

Source: http://chem.ch.huji.ac.il/history/nollet.html

Can’t see that being very popular by modern scientific standards, though I suppose that’s why these people are considered pioneers. They come up with a crazy idea and just go with it.

Public Intervention

We had a couple of cool ideas for this, we settled on creating stickers to raise awareness of public surveillance.

It’s not something I feel particularly strongly about and I felt pretty uncomfortable putting the stickers up. I wasn’t a massive fan of this task.

The Hangover – in four minutes

This was supposed to be a crowd sourcing project, but I suppose our group jumped the gun a bit when we were shown ‘sweding’. We just wanted to have a laugh.

We set out with a rough plan, giddy at the thought of Andy in a jockstrap being on YouTube for everyone to see. We’d managed to get the majority of filming done before the next session, where we were shown sites/projects such as the Johnny Cash Project. A lot of other groups decided to base there’s on the same concept, posting messages and events on Facebook to try and get people involved.

It was too late to try and change our game plan so we stuck with it and filmed a few more scenes. You can see the result below:

It’s not exactly viral, but it’s got close to 100 views! Though I’ve got a feeling Andy may be the majority, checking himself out.

Digital Signature

I chose the font Helvetica as it’s widely regarded the most legible of typefaces, and is generally nice looking.

Didn’t realise we were allowed to use colour, so I used a cutout effect to make it a bit more interesting to look at. Chose to make it all lower-case as it’s informal and approachable, much like myself :)

One Page Website – The Process

decnorton.com

Just putting the finishing touches on my one page website, thought I’d write a post about the kind of process I went through in designing and making it.

Admittedly, I’ve been doing stuff like this for a few years now so I’ve got a bit of a head-start on most, though that’s not to say everything is perfect.

Continue reading

Burning House

Flat mates are burning fish fingers again; what should I try and save this time?

Name: Declan Norton
Age: 19
Location: Plymouth, UK
Occupation: Student

  • Phone – First and foremost. I think we’d all be lost without one!
  • Wallet
  • Blue Folder – a folder containing mementos from different places I’ve been, including a rather large collection of beer labels!
  • External Hard-Drive
  • Laptop

While phone, wallet and laptop can easily be replaced, but the mementos I have stored in the folder and on my hard-drive are irreplaceable to me. I would never be able to get those back.

items

Follow

Get every new post delivered to your Inbox.