Example #1
0
function CompressFiles(array $input_files, $output_file, $compression_type)
{
    if (count($input_files) % 2 > 0) {
        die("ERROR: Invalid entry count in compressed file list</br>");
    }
    $success = true;
    switch ($compression_type) {
        case 0:
            // check that zip compression is available
            if (!class_exists('ZipArchive')) {
                print "ERROR: Zip compression is not available.</br>";
                return false;
            }
            // create a new archive
            $zip = new ZipArchive();
            $result = $zip->open($output_file, ZipArchive::CREATE);
            if ($result !== TRUE) {
                print "ERROR: " . ZipStatusString($result) . "</br>";
                return false;
            }
            // add the files to the archive
            for ($i = 0; $success && $i < count($input_files); $i += 2) {
                if (!file_exists($input_files[$i])) {
                    print "ERROR: A file to compress does not exist.</br>";
                    $success = false;
                } else {
                    $success &= $zip->addFile($input_files[$i], $input_files[$i + 1]);
                }
            }
            if (!$success) {
                print "ERROR: Failed to add all files to archive.</br>";
            }
            // close the archive
            $result = $zip->close();
            if ($result !== TRUE) {
                print "ERROR: " . ZipStatusString($result) . "</br>";
                return false;
            }
            break;
        default:
            print "ERROR: Invalid compression type</br>";
            return false;
    }
    return $success;
}
Example #2
0
                     return 'Invalid argument';
                 case ZipArchive::ER_NOZIP:
                     return 'Not a zip archive';
                 case ZipArchive::ER_INTERNAL:
                     return 'Internal error';
                 case ZipArchive::ER_INCONS:
                     return 'Zip archive inconsistent';
                 case ZipArchive::ER_REMOVE:
                     return 'Can\'t remove file';
                 case ZipArchive::ER_DELETED:
                     return 'Entry has been deleted';
                 default:
                     return sprintf('Unknown status %s', $status);
             }
         }
         $core->log[] = $core->langOut("mup_error") . ": " . ZipStatusString($zHn);
         $core->setLog(CONS_LOGGING_ERROR);
         $ok = false;
     }
     # kill files and zip file
     recursive_del(CONS_FMANAGER . "upload/mpu", true);
 } else {
     // error 9 = unable to make destination path
     $core->log[] = $core->langOut("mup_error") . ": code #" . $ok . " (" . $core->langOut("e20" . $ok) . ")";
     if (is_file($zipFile)) {
         @unlink($zipFile);
     }
     if (is_file($destination)) {
         @unlink($destination);
     }
     $ok = false;
        while ($item_name = $zip->getNameIndex($i)) {
            $zip->renameIndex($i, str_replace($newpmaname . "/", "", $item_name));
            $i++;
        }
        $zip->deleteName($newpmaname . "/");
        //delete last empty dir
        $zip->close();
        //synch updated folder structure
        //extract ZIP
        $res = $zip->open($tmp_folder . $newpmazipfilename);
        echo 'Extraction ' . ($zip->extractTo($target_folder) ? "OK\n" : "Error\n");
        //modifies archive file modification times
        $zip->close();
        //send mail
        $mail_body = "PMA auto update executed to target ver " . $version->version . " released on " . $version->date;
        //mail body
        $subject = "PMA Update executed to " . $version->version;
        //subject
        $header = "From: " . $Name . " <" . $email . ">\r\n";
        //optional headerfields
        if (SEND_NOTIFICATION_EMAIL) {
            mail($recipient, $subject, $mail_body, $header);
        }
    } else {
        echo ZipStatusString($res) . "\n";
        die("Error opening ZIP file.");
    }
} else {
    //do update
    echo "PMA Update not detected. Nothing to do.";
}