ornj/archive-bundle

Symfony2 插件,提供文件存档/压缩的服务

安装: 12

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 3

开放问题: 0

类型:symfony-bundle

dev-master 2013-05-17 23:04 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:31:29 UTC


README

#Ornj ArchiveBundle

此插件提供了一种服务,用于在文件系统中创建文件压缩包。这对于将多个文件作为一个单独的下载项非常有用。目前,唯一支持的压缩类型是通过 PHP 的 ZipArchive 实现的 Zip 压缩,但我打算扩展它以支持其他格式。

安装

通过将此插件添加到您的 composer.json 文件中,在您的 Symfony2 项目中安装此插件。

{
    "require": {
        "ornj/archive-bundle": "dev-master"
    }
}

更新 composer 后,在 app/AppKernel.php 文件中注册插件。

$bundles = array(
   // ...
   new Ornj\Bundle\OrnjArchiveBundle\OrnjArchiveBundle(),
);

使用方法

当前该服务有一个名为 create 的方法,它接受包含以下参数的数组

  • string filename:结果存档的名称
  • array files:应包含在存档中的文件路径
  • string destination:写入存档的位置(如果没有提供,将使用 web/uploads)
  • bool overwrite:是否应该覆盖具有相同文件名的任何存档
$archive = $this->get('ornj_archive.zip');
$created = $archive->create(array(
    'files'         => $files,
    'filename'      => $entity->getId() . '.zip',
    'destination'   => $basePath. '/archives/',
    'overwrite'     => false
));

if ($created === true) {
    return $this->redirect($webPath. '/archives/' . $entity->getId() . '.zip');
}