wamania / zip-streamed-response-bundle
一个用于动态构建和流式传输ZIP文件的symfony响应
1.0
2016-10-17 13:52 UTC
Requires
- php: >=5.3.3
- symfony/framework-bundle: >=2.5
This package is auto-updated.
Last update: 2024-09-09 13:07:29 UTC
README
主要受ZipStream-PHP、PHPZip以及当然,ZIP规范的启发。
安装
在您的 composer.json
文件中添加 wamania/zip-streamed-response-bundle
{ "require": { "wamania/zip-streamed-response-bundle": "dev-master" } }
在 app/AppKernel.php
中注册该包
// app/AppKernel.php public function registerBundles() { return array( // ... new Wamania\ZipStreamedResponseBundle\ZipStreamedResponseBundle(), ); }
使用
在您的控制器中
// .... use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamer; use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerFile; use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerBigFile; use Wamania\ZipStreamedResponseBundle\Response\ZipStreamedResponse; class DefaultController extends Controller { /** * @Route("/", name="homepage") */ public function indexAction() { $zipStreamer = new ZipStreamer('test.zip'); // Auto switch files above switchAboveSize to "big files" ZipStreamer::setAutoSwitch(false/true); // default = true // If autoSwitch==true, files above $switchAboveSize will switch to "big files" ZipStreamer::setSwitchAboveSize(16777216); // default = 16Mb // For big file, size of the buffer for fread ZipStreamerBigFile::setBufferSize(1048576); //default = 1Mb // first string is localpath on hdd, second is pathname in zip $zipStreamer->add( '/home/wamania/photo.jpg', 'images/photo.jpg'); // you can send directly a ZipStreamerFile object $zipStreamer->add( new ZipStreamerFile( '/home/wamania/movie.mp4', 'movies/movie.mp4')); // Big files are send by stream instead of being charged whole in RAM // Big files are NOT compressed $zipStreamer->addBigFile( '/home/wamania/another-big-movie.mp4', 'movies/another-big-movie.mp4'); // or, directly send a ZipStreamerBigFile object $zipStreamer->add( new ZipStreamerBigFile( '/home/wamania/the-big-movie.mp4', 'movies/the-big-movie.mp4')); return new ZipStreamedResponse($zipStreamer); } }