ディレクトリからファイルをダウンロードするダウンロードスクリプトを作成しました。ダウンロードが成功したら、データベースを更新する必要があるため、次のコードを記述します。
$path = $_SERVER['DOCUMENT_ROOT']."/upload/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
$update = mysql_query("Update query");
if($update) {
echo "updated";
}
else {
echo 'error'.mysql_error();
}
exit;
しかし、ダウンロードリンクをクリックし、キャンセルボタンをクリックしたときにブラウザのポップアップがポップアップに表示された場合、ファイルはダウンロードされないため、更新クエリは実行されませんが、上記のコードを使用している場合は、をクリックしても更新クエリが実行したキャンセルボタン。
それで、私のコードの間違いは何ですか?