2017-12-25 2 views
-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); 
} 

を動作しませんが、その後何もない、ないエラー「downloadzipfunctionArray([0] => 1514223591754.xml)よりたくさんのここでのRCHは、入力されました」。 サーバー上にファイルも作成されません。PHPはそれが出力作成しないとzipファイルをダウンロードし、エラーが、

答えて

0

あなたは、この例を見て持つことができます
それは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'; 
} 
?> 
からです
関連する問題