-2

When I click on the file, I can view it in browser. When I click download, it says "failed to load the pdf document".

$file = "uploads/14204-2-002.pdf";
$finfo = finfo_open(FILEINFO_MIME_TYPE); 
$mime = finfo_file($finfo, $file);

header('Pragma: public');
header('Expires: 0');
header('Content-Type: $mime');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.basename($file).'"'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Length' . filesize($file));
ob_clean();
flush();
readfile($file);
curveball
  • 4,320
  • 15
  • 39
  • 49
cijo
  • 27
  • 4

1 Answers1

0

Try this one(HTML5 and no Internet explorer).

In your HTML code you can use this line:

<a href="/images/myw3schoolsimage.jpg" download="w3logo">

Specify a value for the download attribute, which will be the new filename of the downloaded file ("w3logo.jpg" instead of "myw3schoolsimage.jpg")

Moreover you can read this post of this site:

Download files from server php

Ferdinando
  • 964
  • 1
  • 12
  • 23