0

I try to develop something like dropbox(very basic one). For one file to download, it's really easy. what i want is: when client asks me big file, i zip file in server side then send to user. But if file is too big it takes too many times to zip them and send to user.

is there any way to send files while they are compressing?

thanks for your help. Here is my simple sample code

<?php
function createzip($files, $zip_file) {
    $zip = new ZipArchive;
    if($zip->open($zip_file, ZipArchive::CREATE) === TRUE) {
        foreach($files as $file){
        $zip->addFile($file);
    }
    $zip->close();
    return true;
}

    else return false;
}

$ss=array("jj.mp4");
createzip($ss,'archiv.zip');
if(filesize("archiv.zip")>3000){
    $vv=array("archiv.zip");
    createzip($vv,"bbb.zip");
}
?>

use do while loop in if statement. Until file size become a desired value. I don't understand how to use do while loop and does it make it that type of compresses. Please help me out.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Shawon
  • 302
  • 3
  • 15
  • If you indent your code properly you will easily see that that code will not compile or run. Maybe you should look at the code again and see how long it takes to run when it actually compiles – RiggsFolly May 08 '16 at 15:26
  • Oh and zipping a zip file will likely as not just make it a little larger each time. The increase in size being the basic overhead of the structure that must exist inside a zip file for it to know how to unzip itself – RiggsFolly May 08 '16 at 15:28

1 Answers1

0

I use a method like this but I get file names from database if you wanna check and adapt to your codes..

$FList = $dl->select('dosyaYolu0, dosyaYolu1, dosyaYolu2, dosyaYolu3, dosyaYolu4')->table('tb_gelenEvrak')->where('mesajKodu', $filesnorm)->get();


$files = array(''.$FList->dosyaYolu0.'', ''.$FList->dosyaYolu1.'', ''.$FList->dosyaYolu2.'',''.$FList->dosyaYolu3.'', ''.$FList->dosyaYolu4.'');
$zipname = $filesnorm.'.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
    $zip->addFile($file);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
Ivan Barayev
  • 2,035
  • 5
  • 24
  • 30