当前位置: 首页>>代码示例>>PHP>>正文


PHP Zip::AddFile方法代码示例

本文整理汇总了PHP中Zip::AddFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Zip::AddFile方法的具体用法?PHP Zip::AddFile怎么用?PHP Zip::AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zip的用法示例。


在下文中一共展示了Zip::AddFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: agplv3_compliance

function agplv3_compliance()
{
    $paths = get_included_files();
    $src = '';
    $zip = new Zip();
    $zip->OpenZipbuffer($src);
    foreach ($paths as $path) {
        $zip->AddFile($path, 'crewserver/' . basename($path));
    }
    $files = array(basename(WASENTRY, '.php') . '-example.conf', 'readme.txt', 'about.html', 'license.html', 'graphics/waslogo-567x142.png');
    foreach ($files as $file) {
        $path = dirname(WASENTRY) . '/' . $file;
        if (file_exists($path)) {
            $zip->AddFile($path, 'crewserver/' . $file);
        } else {
            $data = sprintf("File '%s' was not found\n", $file);
            $zip->AddData($data, 'crewserver/' . $file);
        }
    }
    $zip->CloseZip();
    return $src;
}
开发者ID:BackupTheBerlios,项目名称:websiteatschool,代码行数:22,代码来源:crewserver.php

示例2: download_source


//.........这里部分代码省略.........
            $directories = array('program' => $CFG->progdir);
            $excludes = array(realpath($CFG->datadir), realpath($CFG->progdir . '/manuals'));
            $archive = 'websiteatschool-program.zip';
            break;
        case 'manual':
            $language = $LANGUAGE->get_current_language();
            $manuals = $CFG->progdir . '/manuals';
            if (!is_dir($manuals . '/' . $language)) {
                if (!is_dir($manuals . '/en')) {
                    logger(sprintf("Failed download 'websiteatschool/manual/%s': 404 Not Found", $language));
                    error_exit404("websiteatschool/{$component}");
                } else {
                    $language = 'en';
                }
            }
            $files = array();
            $directories = array('program/manuals/' . $language => $manuals . '/' . $language);
            $excludes = array(realpath($CFG->datadir));
            $archive = sprintf('websiteatschool-manual-%s.zip', $language);
            break;
        case 'languages':
            $files = array();
            $directories = array();
            $excludes = array();
            $archive = 'websiteatschool-languages.zip';
            $languages = $LANGUAGE->retrieve_languages();
            foreach ($languages as $language_key => $language) {
                if (db_bool_is(TRUE, $language['is_active']) && db_bool_is(TRUE, $language['dialect_in_file'])) {
                    $directories['languages/' . $language_key] = $CFG->datadir . '/languages/' . $language_key;
                }
            }
            if (sizeof($directories) < 1) {
                logger(sprintf("Failed download websiteatschool/%s': 404 Not Found", $component));
                error_exit404('websiteatschool/' . $component);
            }
            break;
        default:
            logger(sprintf("Failed download websiteatschool/%s': 404 Not Found", $component));
            error_exit404('websiteatschool/' . $component);
            break;
    }
    //
    // Step 1 -- setup Ziparchive
    //
    include_once $CFG->progdir . '/lib/zip.class.php';
    $zip = new Zip();
    $comment = $CFG->www;
    if (!$zip->OpenZipstream($archive, $comment)) {
        $elapsed = diff_microtime($time_start, microtime());
        logger(sprintf("Failed download '%s' (%0.2f seconds): %s", $archive, $elapsed, $zip->Error));
        return FALSE;
    }
    //
    // Step 2 -- add files in the root directory (if any)
    //
    if (sizeof($files) > 0) {
        foreach ($files as $file) {
            $path = $CFG->dir . '/' . $file;
            if (!file_exists($path)) {
                logger(sprintf("%s(): missing file '%s' in archive '%s'", __FUNCTION__, $path, $archive), WLOG_DEBUG);
                $data = sprintf('<' . '?' . 'php echo "%s: file was not found"; ?' . '>', $file);
                $comment = sprintf('%s: missing', $file);
                if (!$zip->AddData($data, $file, $comment)) {
                    $elapsed = diff_microtime($time_start, microtime());
                    logger(sprintf("Failed download '%s' (%0.2f seconds): %s", $archive, $elapsed, $zip->Error));
                    $zip->CloseZip();
                    return FALSE;
                }
            } else {
                if (!$zip->AddFile($path, $file)) {
                    $elapsed = diff_microtime($time_start, microtime());
                    logger(sprintf("Failed download '%s' (%0.2f seconds): %s", $archive, $elapsed, $zip->Error));
                    $zip->CloseZip();
                    return FALSE;
                }
            }
        }
    }
    //
    // Step 3 -- add directories to archive
    //
    foreach ($directories as $vpath => $path) {
        if (!download_source_tree($zip, $path, $vpath, $excludes)) {
            $elapsed = diff_microtime($time_start, microtime());
            logger(sprintf("Failed download '%s' (%0.2f seconds): %s", $archive, $elapsed, $zip->Error));
            $zip->CloseZip();
            return FALSE;
        }
    }
    //
    // Step 4 -- we're done
    //
    if (!$zip->CloseZip()) {
        $elapsed = diff_microtime($time_start, microtime());
        logger(sprintf("Failed download '%s' (%0.2f seconds): %s", $archive, $elapsed, $zip->Error));
        return FALSE;
    }
    logger(sprintf("Download '%s' (%0.2f seconds): success", $archive, diff_microtime($time_start, microtime())));
    return TRUE;
}
开发者ID:BackupTheBerlios,项目名称:websiteatschool,代码行数:101,代码来源:main_file.php


注:本文中的Zip::AddFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。