readfile在新页面中打开,而不是在弹出窗口中下载文件

hi i need help i am using the code below from php.net to allow site visitors download documents on my site

<?php

   $file = $_GET['file'];;

   if (file_exists($file)) {
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename='.basename($file));
   header('Expires: 0');
   header('Cache-Control: must-revalidate');
   header('Pragma: public');
   header('Content-Length: ' . filesize($file));
   ob_clean();
   flush();
   readfile($file);
   exit;
   }
?>

my problem is that instead of the code outputting a dialog box in order for me to save/download the document as outlined here http://www.php.net/manual/en/function.readfile.php the code opens up in a new page showing abnormal data...the code works perfectly on xampp localhost but not on the server

what might be the problem??

The code seems to be perfect. My thoughts is that the configuration of php.ini in the server and the xampp might be different.

My suggestion is to run <?php phpinfo(); ?> in both server and xampp and compare the configuration and match the xampp's configuration in the server.