예제 #1
0
function add_directory_to_zip(&$z, $dir, $base_dir = NULL)
{
    if (empty($z)) {
        _die('Error in ZIP Parameter');
    }
    if (is_null($base_dir)) {
        $base_dir = trim($dir, '/');
        $base_dir = trim($base_dir, '\\');
    }
    foreach (scandir($dir) as $file) {
        if (in_array($file, array('.', '..'))) {
            continue;
        }
        if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
            add_directory_to_zip($z, $dir . DIRECTORY_SEPARATOR . $file, $base_dir);
        } elseif (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
            // directory for the ZIP file
            $zDir = str_replace($base_dir, '', $dir);
            $zDir = trim($zDir, '/');
            $zDir = trim($zDir, '\\');
            $zDir .= empty($zDir) ? '' : '/';
            $z->addFile($dir . DIRECTORY_SEPARATOR . $file, $zDir . $file);
            _log('Added "' . $dir . DIRECTORY_SEPARATOR . $file . '" to ZIP');
        }
    }
}
예제 #2
0
function create_source_zip()
{
    // get the version
    $v_res = $GLOBALS['db']->query('select `version` from `version` limit 1')->fetch();
    $version = $v_res['version'];
    if (empty($version)) {
        $version = '';
    }
    $zip_filename = _DIR_ROOT . '/source/latest' . $version . '.zip';
    define('_SOURCE_ZIP_FILE', $zip_filename);
    if (file_exists($zip_filename)) {
        if (($fp = @fopen($zip_filename, 'r')) !== false) {
            $stats = fstat($fp);
            fclose($fp);
            // check if the source was created in the last hour
            if (time() - $stats['mtime'] <= 3600) {
                return;
            }
        }
        rename($zip_filename, _DIR_ROOT . '/source/latest' . time() . '.zip');
    }
    // Create the latest source of the application
    // in a ZIP archive
    $z = new ZipArchive();
    $z->open($zip_filename, ZipArchive::CREATE);
    add_directory_to_zip($z, _DIR_ROOT);
    // define a constant with the path to the file
    define('_SOURCE_ZIP_FILE', $zip_filename);
}