나는 디렉토리에서 파일을 다운로드 할 다운로드 스크립트를 작성했다. 성공적인 다운로드가 완료되면 데이터베이스를 업데이트해야 다음 코드를 작성할 수 있습니다.성공적으로 다운로드 할 때 데이터베이스를 업데이트하는 방법은 무엇입니까?
$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;
하지만 다운로드 링크를 클릭하고 브라우저의 팝업 내가 취소 버튼을 클릭하면 팝업으로 나타납니다 때 파일은을 사용하여 때 다운로드 것이 아니라, 그것은 업데이트 쿼리를 실행하지 말아야 위의 코드는 취소 버튼을 클릭해도 업데이트 쿼리가 실행됩니다.
내 코드의 실수는 무엇입니까?
나에게 내 문제의 해결책을 말할 수있는 하나? – Ahmad