A Better Unzip

A while back I told you about a neat way to unzip files on the server.  Today I learned of a method that does the same thing, however this new method will overwrite files on the server.  This is great if you need to revert to an old version of WordPress, as I had to do this morning.

Just create a file called “unzip.php” and paste the following code into that file:

       system('unzip -o ' . $file);
    // create a handler to read the directory contents
    $handler = opendir(".");
    echo "Please choose a file to unzip: " . "
"; // A blank action field posts the form to itself echo '
'; $found = FALSE; // Used to see if there were any valid files // keep going until all files in directory have been read while ($file = readdir($handler)) { if (preg_match ("/.zip$/i", $file)) { echo ' ' . $file . '
'; $found = true; } } closedir($handler); if ($found == FALSE) echo "No files ending in .zip found
"; else echo '
Warning: Existing files will be overwritten.

'; echo "
"; ?>

Then upload unzip.php to the same directory as the file you want to unzip.

Then navigate to http://yourdomain.com/unzip.php and select the file you want to unzip.

Pretty neat, eh?

Many thanks to Learn CPP.

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to twitter.com/tobycryns and twitter.com/themightymo

Follow Toby's contributions on Github and WP.org.