Tag Archives: joomla

ftp unzip

Here’s a little trick for web masters out there who upload and extract wordpress, prestashop, joomla or any other open source products with loads of fiddly little files that normally take an age to upload via ftp.

The usual case is you extract the zip locally and upload the few thousand files via FTP and even with a nice wide broadband pipe it can take time to upload each file individually. A better solution would be to upload the zip file via ftp and then log in to your server using ssh or whatever to extract the file, but sometimes it can be a pain on shared hosting to set up ssh and then go through setting up logins etc. or maybe you don’t have that option at all.

Here’s an alternative that might save a few minutes. Look, I’m lazy OK!

What I do is run a little script on the server that calls a method on the ZipArchive class.

The example below extracts the prestashop zip file to the same directory that the archive is in.

//new zip archive object
$zipArchive = new ZipArchive;

//file to unzip in same directory as this script
$fileToUnzip = "prestashop_1.5.3.1.zip";

//retrieve current path from the zip
$unzipPath = pathinfo(realpath($fileToUnzip), PATHINFO_DIRNAME);

//open and extract the zip file
if ($zipArchive->open($fileToUnzip) === TRUE) 
    echo "Unzipping $file to $unzipPath...<br/>";
    echo "Hey presta!!!";
    echo "Cannot open $fileToUnzip... Doh!";

If the zip file extracts to a subfolder it will only take seconds to copy the files back to the root directory, if that’s what is required.

Might be handy for someone.