RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Unzip a file with PHP

There's a ton of really good libraries for handling the zipping and unzipping of files. The following solution is super-simple in nature and uses PHP's ZIP extension that "enables you to transparently read or write ZIP compressed archives and the files inside them". The same class can be used to zip files and perform a number of other operations.

1
<?php 
2
/*
3
 Unzip a file with PHP
4
 http://www.beliefmedia.com/code/php-snippets/unzip-file-php
5
*/
6
 
7
function beliefmedia_unzip_file($file, $location = 'extracted/') {
8
  $zip = new ZipArchive;
9
  $result = $zip->open($file);
10
 
11
  if ($result === true) {
12
    $zip->extractTo($location);
13
    $zip->close();
14
    return true;
15
    } else {
16
    return false;
17
  }
18
}
19
 
20
/* Usage */
21
echo beliefmedia_unzip_file($file = 'some-zip-file.zip') ? 'Successful' : 'Error';

To zip a file, look at the ZipArchive::addFile documentation.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment