RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

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 complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

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

Leave a comment