目次 |
---|
・ファイルダウンロード(一括) ・サンプルコード ・サンプル |
(php部 :download_comp.php ) <?php header( "Content-Type: application/octet-stream" ); header( "Content-disposition: attachment; filename=comp.zip" ); require_once('zip.lib.php'); // クラス作成 $zipfile = new zipfile(); // ダウンロード元ファイル1を設定します。 //ファイルパス(絶対パス、ファイル名まで含む)を指定します。 $filename1 = 'path/Sunset.jpg'; // 保存時のファイル1の名前を設定します。 $fName1 = 'Download_Sunset.jpg'; // ファイルをバイナリで読んで、変数にセット $handle = fopen($filename1, "rb"); $contents = fread($handle, filesize($filename1)); fclose($handle); // 追加 $zipfile->addFile($contents, $fName1); // ダウンロード元ファイル2を設定します。 //ファイルパス(絶対パス、ファイル名まで含む)を指定します。 $filename2 = 'path/test.txt'; // 保存時のファイル2の名前を設定します。 $fName2 = 'Download_Test.txt'; // ファイルをバイナリで読んで、変数にセット $handle = fopen($filename2, "rb"); $contents = fread($handle, filesize($filename2)); fclose($handle); // 追加 $zipfile->addFile($contents, $fName2); // zip をバイナリで変数にセット $zip_buffer = $zipfile->file(); print $zip_buffer; ?> (html部 : download_comp.html ) <form method="post" action="download_comp.php"> <input type="submit" value="ダウンロード"> </form>