Skip to main content

How to unpack ZIP files in a web space

| Gianluca Gabella | Tips & Tricks
share on facebook share on twitter share on linkedin

Index:


When we download Joomla! (or Wordpress, or Prestashop...) from the official website we end up with a ZIP file containing all the basic and installation files.

The 'standard' procedure involves unpacking (i.e. expanding the compacted files using a dedicated programme such as WinRAR or WinZIP) the archive, and then uploading it to the web server using an FTP programme such as FileZilla.

Is this the smartest method?

Of course not!

Uploading thousands of small files via FTP is infinitely slower than uploading a single, even very large file. This is because time is lost in all the stages of FTP communication between client and server.

The ideal would therefore be to upload the compacted archive (in ZIP format) to the server and then unzip it directly. This last step is simple, but not trivial. In fact, on the server, there are no fast and intuitive ways to unzip a file, such as the classic 'right click -> extract'. It is therefore necessary to resort to external expedients.

OK, I uploaded the ZIP to the server, now what?

It is very simple, just upload a PHP file containing a script that takes care of extracting the zip file:

  1. Let's create a file on our desktop and call it, for example, extractor.php
  2. Copy this code inside:
    <?php
      $zip = new ZipArchive;
      $path = getcwd();
      if ($zip->open('FILENAME.zip') === TRUE) {
        $zip->extractTo($path);
        $zip->close();
        echo 'extraction complete';
      }
    ?>
  3. We modify line 4 by inserting the name of the ZIP file we wish to unzip inside the quotes (instead of FILENAME.zip)
  4. Let's save
  5. Sending to the server via FileZilla

At this point we should end up on the server with 2 files:

  • FILENAME.zip
  • extractor.php

Done! Now what? How do I proceed?

That's it! Now you simply have to go with the browser to your website and call up the file extractor.php

If, for example, you have uploaded everything to www.ilmiosito.com you simply have to type the following address www.ilmiosito.com/extractor.php into the URL space of your browser (any browser will do!).

If everything went well, the words "extraction completed" should appear after a few seconds. This means that your ZIP has been successfully unpacked on the server.

 

ATTENTION: This is not the end of the story! After unpacking the ZIP, remember, again from FileZilla, to delete it from the server and to delete the file extractor.php! This is because otherwise anyone in the future could return to that file and restart the file extraction. Delete them!!!


If you liked this article, please share it!

share on facebook share on twitter share on linkedin
condividi su Facebookcondividi su Twittercondividi su LinkedIncondividi su WhatsAppcondividi su Telegram