dポイントプレゼントキャンペーン実施中!

pdfファイルの連続ダウンロードを作っています。

複数ファイルをチェックボックスで指定して
指定した数のファイルをダウンロードさせるようにしているのですが
全部のファイルがダウンロードできません。

複数ファイルの選択 download.html
チェックボックスでファイルの複数選択
それをJavaScriptでオンになっていたらダウンロードさせる。
window.open で呼び出す先は <iframe>
=============================
<script language="JavaScript">
<!--
function down() {
if (document.f1.file001.checked == true) {
newwin = window.open("1.php","my1");
}
if (document.f1.file002.checked == true) {
newwin = window.open("2.php","my2");
}
if (document.f1.file003.checked == true) {
newwin = window.open("3.php","my3");
}
if (document.f1.file004.checked == true) {
newwin = window.open("4.php","my4");
}
if (document.f1.file005.checked == true) {
newwin = window.open("5.php","my5");
}
}
//-->
</script>
中略
<form name="f1">
<input type="checkbox" value="on" name="file001">
<input type="checkbox" value="on" name="file002">
<input type="checkbox" value="on" name="file003">
<input type="checkbox" value="on" name="file004">
<input type="checkbox" value="on" name="file005">
<input type="button" value="ダウンロード" onclick="down()">
</form>
中略
<iframe src="index.html" name="my1" width="5" height="3" style="width:1px;height:1px;visibility:hidden;">
<iframe src="index.html" name="my2" width="5" height="3" style="width:1px;height:1px;visibility:hidden;">
<iframe src="index.html" name="my3" width="5" height="3" style="width:1px;height:1px;visibility:hidden;">
<iframe src="index.html" name="my4" width="5" height="3" style="width:1px;height:1px;visibility:hidden;">
<iframe src="index.html" name="my5" width="5" height="3" style="width:1px;height:1px;visibility:hidden;">
======================================
ダウンロード用のファイル 1.php
<?php
// ダウンロードさせる元ファイル
$filepath = "filepdf/file01.pdf";
// 保存時のファイル名(デフォルト)
$filename = "ファイル1.pdf";
// HTTPヘッダ送信
header("Content-length: " . filesize($filepath));
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"{$filename}\"");
// ファイルを読み込んで出力
readfile($filepath);
?>
==================================
上記の用にソースを書いて複数ファイルのダウンロードを行っていますが、
1個ずつ選択した時はダウンロード成功
2個選択した時、2個目がダウンロードしない
3個以上選択した時、ダウンロードできないファイルが出てくる。
チェックを同じにして、数回試すと
その度にダウンロードされないファイルが違っている。
なぜダウンロードされないファイルが出てくるのかがわかりません。
複数ファイルの連続ダウンロードでは、ダウンロードできるファイルの
サイズに限りがあるとか、何かあるのでしょうか?

A 回答 (1件)

試していませんので、あくまで「・・ではないだろうか?」程度ですが、


newwin = window.open("1.php","my1");
と、オープンしたウインドウを全て同じ newwin で受けています。
ですので、処理途中のウィンドウが次のウインドウに置き換わってしまうためではないでしょうか。
newwin をそれぞれ別の名前にしてみては。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!