1

フォルダ内のファイルをダウンロードしようとしていますmy_folder。ファイルにzipファイルを作成し、phpを使用してダウンロードします。これが私が試したものです。

<?php

$path = '/my_folder/path/';
$handle=opendir($path); 
$files = array();
while(false!==($file = readdir($handle)))
 {
    $files[] = $path . $file;
 }
$zipname = 'file.zip';
$zip = new ZipArchive;
if($zip->open($zipname, ZipArchive::CREATE) == TRUE){
    foreach ($files as $file) {
      $zip->addFile($file);
    }
    $zip->close();
}

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=filename.zip');
header('Content-Length: ' . filesize($zipname));
header("Pragma: no-cache"); 
header("Expires: 0");
readfile($zipname);
unlink($zipname);
?>

それは完全にうまくいくようです。zip ファイルをダウンロードしますが、zip を解凍しようとすると、パスワード ダイアログ ボックスにエラー メッセージが表示Archieve non readable; Would you like to try a password されます。

4

0 に答える 0