Themergency fooplugins.com

UNZIP Files On Your Server

| 13 Comments

If you want to you can skip the explanation and go straight to the Step By Step walkthrough.

A Few Questions First

How often do you FTP a new wordpress install to your live server?
Well if you are a freelance web designer or developer then I would say quite often. Every time you put a new site live you have to upload the entire wordpress site which can be 800+ files.

How long does it you take to upload your whole wordpress site?
The last time I timed it (with a fresh install of wordpress 3 beta 1), it took over 10 minutes to upload the 815 files (10.7 MB).

Why does it take so long?
Besides my really slow internet connection, it’s really FTP’s fault. Depending on the software you use (I use FileZilla), you can choose how many concurrent transfers, but when you are uploading 800+ files, being able to transfer 10 files at once still can take a while. Also, the file size is a factor and the fact that most of the files being transferred are php files means that there is major room for improvement from a compression point of view.

The Obvious Next Step - ZIP

Obviously we need to compress the files into a single zip archive. We could then upload the much smaller file to the server. The only problem left is that we need to unzip the file once it has been uploaded onto the server. And one way to do that would be to write some PHP code to do this task for us. But since you are reading this article in order to save time, I am guessing you don’t have time to write this code either.

The Solution

PHP UnZIP comes to the party and fills this gap. It allows you to FTP your much smaller zip file onto your server and then unzip it in 1 click. All the logic is contained in a single file ‘unzip.php’ which weighs in at 98KB. So all we need to do is FTP our zip archive together with the unzip.php file and we can do exactly what we have set out to.

Step By Step

  1. Download unzip.zip and extract unzip.php.
  2. Zip your wordpress install (or whatever else) into a single zip.
  3. Upload your new zip together with unzip.php to your server via FTP. Make sure the zip file is in the correct directory on your server where you would like it to be extracted.
  4. CHMOD unzip.php to 777. I do this with my FTP program (FileZilla) by right-clicking on the file and selecting ‘File Permissions’. (for windows you will have to allow full control or modify secutiry permission to the necessary user)
  5. Open the file unzip.php in your browser.
  6. Browse your server’s directories and click the zip file to UnZIP it!
  7. Delete both the zip file and unzip.php.
  8. Decide what to do with the extra time you now have.

Comparison Of Before And After

Before After
File Count 815 2
File Size 10.7 MB 3.2 MB
Time Taken 14 mins 2 mins

UnZIP In Action

Tools Used

  • The code that handles the zip extraction is the PhpConcept Library - Zip Module 2.8.2 which you can download at http://www.phpconcept.net/pclzip/pclzip-downloads
  • I minified the zip library with this cool PHP minifier tool.
  • I ‘embedded’ the images used in unzip.php with this cool tool.

Summary

You can now upload your entire WordPress website to your server in a quarter of the time or less using UnZIP. I hope you find this useful, and please let us know what you think or if there are ways to improve it.

Download here : unzip.zip

11 comments
  Livefyre
  • Get Livefyre
  • FAQ
FrancescoGiossi
FrancescoGiossi

I love you!

Thanks for this script, you saved 30 minutes of my life!

DannyLabonte
DannyLabonte

Doesn't work here. Just like Chris, it says "Beginning extracting..." then it stalls after a few files extracted. No image files in my case, just the standard Wordpress wp-admin and wp-includes folders. Any idea what happens?

Cicero Monteiro
Cicero Monteiro

Thanks for saving a lot of time here. Keep up the good work!

hari1

This works like a charm, i want to compress a folder on server in a similar fashion using FileZilla i want to download it. Is it possible? Solution would be great. Thanks in advance

poulR
poulR

I get an error opening unzip.php:

"Warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(/var/www/xxxx/html) is not within the allowed path(s):"

- seems like a trailing slash is missing at the end of the path?

Chris
Chris

Why set the php permissions to 777? I uploaded mine and left it set to 644. and it works fine. 777 seems awfully dangerous to me.

I am seeing one small problem though. I'm trying to unzip a file size 12.21 MB in size, with 91 image files. The page "Starting to decompress..." has displayed now for about twenty minutes, while only 23 files have upacked. It seems to have stalled. (Actually, it totally stopped)

Any idea why this might happen? php.ini max file size and max post are both set to 200 MB. Is it possible the resource limits might need to be increased? My php.ini setttings for that are now:

max_execution_time = 30
max_input_time = 60
memory_limit = 32M

This is on a shared host, and I did take a look and saw cpu throttling during this period (or close to it anyway). Ultimately I will be using this script on a private dedicated server, so if throttling is what caused this, I may not need to worry about it.

Adil

nice tutorial...but when i try to unzip the file.it gives the following error

"Browse your server directories to find the zip file you want to unzip. Click the file to unzip it. Please make sure you have given appropriate permissions! Abort unzip.php : Missing zlib extensions".. Kindly help out

Trackbacks

  1. How To Install WordPress Themes | The Blogging Expert says:

    [...] UNZIP Files Oח Yουr Server | Themergency [...]

  2. wp-popular.com » Blog Archive » UNZIP Files On Your Server | Themergency says:

    [...] here to see the original: UNZIP Files On Your Server | Themergency Tags: cpanel, php, [...]