在升级到最新版本的Joomla之后,我正在从一个网站上下载的内容不正确。
示例页面: http : //www.pacificpolicy.org/index.php?option=com_content&view=article&id= 259: mic-paper&catid= 39: rokfeature
在第一次访问时,他们正在处理正确的内容处理,但任何进一步的访问PDF文件正在被加载为文本/ HTML(即在屏幕上显示文件的内容)。
如何强制浏览器在每次访问时正确加载PDF? 我对PHP&http头的知识是相当基本的,所以我可以使用一些帮助来诊断这个。
主机是一个LAMP服务器,Joomla是1.5.22,文档pipe理插件是Rubberdoc。
第二次访问的响应标题如下:
Date: Thu, 16 Dec 2010 04:29:03 GMT Server: Apache/XXx X-Powered-By: PHP/xxx P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM" Etag: db71388c6fc952682ae2fd733d4b09c5 Content-Encoding: gzip X-Content-Encoded-By: Joomla! 1.5 Expires: Mon, 1 Jan 2001 00:00:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Host Last-Modified: Thu, 16 Dec 2010 04:29:03 GMT Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8
下载文档是从一个PHP文件中调用,
<?php // Check to ensure this file is included in Joomla! defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); /** * HTML View class for the RubberDoc component * * @static * @package Joomla * @subpackage RubberDoc * @since 1.0 */ class RubberDocViewDoc extends JView { public function display($tpl = null) { global $mainframe, $option; $id = JRequest::getInt('id'); if(!$id) { JError::raiseError(404, 'Page Not Found'); return; } $model =& $this->getModel('doc'); $model->hit(); $data =& $model->getData(); $fileName =& $data->get('file'); $dirname = $mainframe->getParams('com_rubberdoc')->get('rubberdoc_dir', 'rubberdoc'); $filePath = JPath::clean( JPATH_SITE.DS.$dirname.DS.$fileName ); if( !JFile::exists( $filePath ) ) { JError::raiseError(404, 'Page Not Found'); return; } $fileName = $data->get('file'); $extension = array_pop( explode('.', $fileName) ); $fileName = $data->get('alias').'.'.$extension; $fileContent = JFile::read( $filePath ); $fileSize = strlen($fileContent); require(JPATH_COMPONENT.DS.'helpers'.DS.'mime.mapping.php'); $mime = $mime_extension_map[$extension]; //application/octet-stream // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } $doc =& JFactory::getDocument(); $doc->setMimeEncoding( $mime ); $doc->setModifiedDate( $data->get('modified') ); $doc->render(); header('Content-Disposition: attachment; filename="'.$fileName.'" '); header('Content-Length: '. $fileSize); header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); if( ! ini_get('safe_mode') ) { // set_time_limit doesn't work in safe mode @set_time_limit(0); } echo $fileContent; } }
谢谢,尼古拉维拉,瓦努阿图
这很难说,但我会怀疑,在第一次访问他们正在由java代码,其中设置正确的MIMEtypes服务。 之后,可能会发生一些caching,而不是设置正确的MIMEtypes。 查看是否有任何PDF文件在磁盘上浮动。 如果是这样,你需要看看Apache的configuration,而不是你的代码。