PHP snippets

Примеры PHP кода

Распаковка zip-архива

Файл functions.php

<?php
    function unzip($location, $newLocation) {
        if(exec("unzip $location", $arr)) {
            mkdir($newLocation);
            for ($i = 1; $i < count($arr); $i++) {
                $file = trim(preg_replace("~inflating: ~", "", $arr[$i]));
                copy($location . '/' . $file, $newLocation . '/' . $file);
                unlink($location . '/' . $file);
            }
            return true;
        }else{
            return false;
        }
    }
?>

Файл extractZip.php

<?php
include 'functions.php';
if(unzip('zippedfiles/test.zip', 'unzipped/myNewZip')) {
    echo 'Success!';
} else {
    echo 'Error';
}
?>