Shiva Tiwari

Shiva Tiwari

  • NA
  • 73
  • 4.7k

download file and redirect to page

Jun 4 2020 2:02 AM
$select = "SELECT * FROM `success-stories` where id='$id'";
$result = $conn->query($select);
$row = $result->fetch_assoc();
$file = $row["download_pdf"];
$file_arr = explode("/", $file);
$path = $file_arr[0] . "/" . $file_arr[1] . "/" . $file_arr[2];
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Pragma: no-cache');
header('Content-Length: ' . filesize($file));
$file1 = $path;
// this doesn't really matter.
$fp = fopen($file1, "r");
while (!feof($fp)) {
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
header("location:download-form.php?msg=story downloaded");

Answers (1)