php管理的PDF下载不起作用


PDF download managed by php is not working

我有以下功能:

if (isset($_REQUEST["f"]))
{
  //get file details from database
  $fileID=$_REQUEST["f"];
  $sql = "select * from sds_files where file_id = " .fquery_sanitize($fileID);
  $result = fquery_db($sql);
  //$file_extension = strtolower(substr(strrchr($filename,"."),1));
  if(mysql_num_rows($result) >0)
  {
    $row = mysql_fetch_assoc($result);
    $filename = $row['file_name'];
    $file = file_GetPath($fileID); 
    header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Type: application/octetstream');
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($file));
    header("Content-disposition: attachment; filename='"".basename($filename)."'"");
    readfile("$file");                
  }
  else
  {
    echo "File cannot be found";
  }
}
else
{
    echo "No file selected";
}

这会得到一个文件,可以是任何类型的.xls、.doc.dox、.pdf等…

对于大多数pdf来说,这段代码是有效的,但在个别情况下,我会收到用户声称他们收到了一个错误,比如"找不到文件"。但是,如果我给他们一个文件的直接链接,它就可以正常工作。

我不知道问题出在哪里,我强制使用了附件类型,这样他们就被迫保存它,而不是在浏览器中出现,就像在ie6中一样,如果你使用adobe插件而不是程序,它往往会崩溃。

编辑:

该错误是adobe acrobat错误的一部分,与PHP或apache错误代码无关。更多与客户相关的信息。我显示代码是因为用户的行为不同。

我对它做了更多的研究,看起来直接链接有一个MIME类型的PDF,adobe告诉浏览器属于adobe阅读器,我想知道另存为是否会迫使相同的行为导致错误。

任何帮助都将不胜感激!

好的,它似乎被隔离到:

标题("内容处置:附件;……

这迫使浏览器下载到内容,而不使用浏览器插件,这会导致某些用户设置的权限问题。