1
我有一个接收参数的脚本,然后将文件下载到客户端浏览器。该文件不位于文件夹下可访问的文件夹下Php文件下载在顶部放了两行,换行
当我的脚本执行pdf的工作正常,但词docents不。
我用记事本++检查了文件,显示符号和pdf和文档都有两行,包含根据记事本++的LF(看起来像Adobe Reader更宽容)。
我检查了我能想到的所有东西。我试图通过文件修剪befor输出,检查没有空白之前打开php标记,尝试创建一个文件作为数组循环每个元素,并且不回显最后两个,如果他们包含“\ n”,
可能这是Apache设置的问题?
示例脚本:
<?php
class TrainingDatabase_IndexController extends Zend_Controller_Action
{
public function downloadAction()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// Get filepath and decode it from get param
$filepath = urldecode($this->_request->getParam('directory'));
// Return the basename for save as filename
$filename = basename($filepath);
// Set the headers
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/octet-stream');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
header('Content-Length: '.filesize($filepath));
// Make sure nothing is left in the browser
ob_clean();
flush();
// Output the file
readfile($filepath);
}
}
而不是将内容类型设置为八位字节流,请尝试使用application/msword for Word和application/pdf for PDF文件。此外,$ filepath变量是否仅包含目录的路径而不包含文件本身?然后它可能是文件大小($ filepath)正在搞点东西 – edwardmp
所有包含的文件最后都有'?>'结尾吗?因为之后的空白也会导致这种情况。 –
您好,我没有任何构成路线的文件中有任何尾随?>标签。我也保证没有文件中的空白。谢谢,ronnie –