Hi, i have a problem in downloading pdf files that is when i click the download button it just download a text file contains unreadable and unrecognizable words and numbers , so can any one help me to solve this problem

my code to download a pdf file is :

$DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT'];
	  
 	  $root_file = "$DOCUMENT_ROOT"."mysite2/downbooks/";
  	  
  	  $down_url = $root_file.$book_name.".pdf";

  	  header('Content-Type: application/force-download');
  	  header('Content-Type: application/octet-stream');
  	  header('Content-Type: application/download');
 	  header('Content-disposition: attachment; filename='.basename($down_url)."'");
  	  header('Content-Type: application/pdf');
          header('Content-Transfer-Encoding: binary');
  	  //header('Content-Length: ' . filesize($down_url));
  	  @readfile($down_url);
  	  exit(0);

Random thought, but try removing the ."'" from the end of line 10.
R.

I tried to this before but it doesn't work , any random thoughts may help...thanks

$DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT'];
	  
 	  $root_file = "$DOCUMENT_ROOT"."mysite2/downbooks/";
  	  
  	  $down_url = "$root_file.$book_name.pdf";
          header("Expires: 0");
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0")
          header("Content-Description: File Transfer");    
  	  header("Content-Type: application/pdf");
 	  header("Content-disposition: attachment; filename=$book_name.pdf");
          header("Content-Transfer-Encoding: binary");
  	  header('Content-Length: ' . filesize($down_url));
  	  @readfile($down_url);
  	  exit;

Thanks a lot adatapost it some works fine but when i tried to open the PDF file adobe reader said that the file could be damaged or not a supported file type and the downloaded file size is not the actual size of the original file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.