-2
function downloadZipFunction() {
    echo 'entered downloadzipfunction';
    //$files = $myArray;
    global $files;
    print_r($files); echo 'plis rch here';
    # create new zip opbject
    $zip = new ZipArchive();
    echo "before tempnam";
    # create a temp file & open it
    $tmp_file = tempnam('./docs/','tmp');
    echo "after tempnam";
    echo $tmp_file;
    $zip->open($tmp_file, ZipArchive::CREATE);

    # loop through each file
    foreach($files as $file){
        echo "entered foreach";
        # download file
        $download_file = file_get_contents("docs/".$file);
        echo "docs/".$file;
        #add it to the zip
        $zip->addFromString(basename($file),$download_file);
        echo basename($file);
    }

    # close zip
    $zip->close();

    # send the file to the browser as a download
    header('Content-disposition: attachment; filename= docs_$prop.zip');
    header('Content-type: application/zip');
    readfile($tmp_file);
    echo $tmp_file;
    //unlink($tmp_file);
}

It outputs 'entered downloadzipfunctionArray ( [0] => 1514223591754.xml ) plis rch here' but nothing else after that, no error. No file is created on the server as well.

1 Answers1

0

You can have a look at this example
It is from the php.net

<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFromString('test.txt', 'file content goes here');
    $zip->addFile('data.txt', 'entryname.txt');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>
halojoy
  • 225
  • 2
  • 7