Largely inspired by ZipStream-PHP, PHPZip and of course, the ZIP specifications.
Require wamania/zip-streamed-response-bundle
into your composer.json file:
{
"require": {
"wamania/zip-streamed-response-bundle": "dev-master"
}
}Register the bundle in app/AppKernel.php:
// app/AppKernel.phppublicfunctionregisterBundles()
{
returnarray(
// ...newWamania\ZipStreamedResponseBundle\ZipStreamedResponseBundle(),
);
}In your controller :
// ....useWamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamer;
useWamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerFile;
useWamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerBigFile;
useWamania\ZipStreamedResponseBundle\Response\ZipStreamedResponse;
class DefaultController extends Controller
{
/** * @Route("/", name="homepage") */publicfunctionindexAction()
{
$zipStreamer = newZipStreamer('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(
newZipStreamerFile(
'/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(
newZipStreamerBigFile(
'/home/wamania/the-big-movie.mp4', 'movies/the-big-movie.mp4'));
returnnewZipStreamedResponse($zipStreamer);
}
}