barracudanetworks / ArchiveStream-php

Archive streaming library for PHP
Other
77 stars 27 forks source link

Support request loop over files in folder #41

Open murphy1484 opened 7 years ago

murphy1484 commented 7 years ago

Can someone help me out and tell me what is wrong with following code? The .tar file being downloaded is only 14kb while the "files" folder contains a video of 800MB.

`<?php include 'vendor/autoload.php';

// Create a new archive stream object (tar or zip depending on user agent)
$zip = \Barracuda\ArchiveStream\Archive::instance_by_useragent('example');

$directory = 'files';
$files = array_diff(scandir($directory), array('..', '.', '.DS_Store'));

foreach ($files as $file) {
    $fileSize = filesize($directory."/".$file);
    $filePath = $directory."/".$file;
    $zip->init_file_stream_transfer($filePath, $fileSize);
    $zip->stream_file_part($data);
    $zip->complete_file_stream();
}

// Finish the zip stream
$zip->finish();

?>`