繁体   English   中英

如何在Mac上的PHP中设置Content-type?

[英]How to set Content-type in php on mac?

我有问题。 这是我的php代码:

include "connection.php";

$patternJPG = '/.pdf$/i';
$gfs = $db->getGridFS();
$collection=$db->Children;
$selected = array('_id'=> new MongoId($_GET['id']));
$cursor=$collection->find($selected);
foreach($cursor as $b){
        $id1 = $b["photoID"];

        $criteria = array("_id" => New MongoId ($id1));
        $nameOriginal = $gfs->findOne($criteria)->file['filename'];
        if(preg_match($patternJPG, $nameOriginal)){
        $row = $gfs->findOne($criteria)->getBytes();
        $mimeType = 'Content-type: application/pdf';
        header("Content-Length: " . strlen($row)); 
        header($mimeType); 
        ob_end_clean(); 
        flush();
        echo($row);
        }

        }

该代码从字面上可以在Windows平台上使用。 当我尝试在Mac上运行该代码时,它不起作用。 我认为应该改为在所有平台上使用代码。 一直这样,我从来没有发现过这样的问题。 我有在Windows上运行的代码,在Mac上也可以运行。 请有人帮我解决此问题。

视窗

苹果电脑

关于类似问题有一篇文章

嗯,Chrome应该是一种基本的浏览器,可以通过扩展自定义您的需求。 我们的Web App Store具有许多免费的便捷花色扩展,这些扩展使您可以在浏览器中直接查看PDF。

请尝试安装插件以在MacOS上查看Chrome中的PDF文件

https://chrome.google.com/webstore/search/pdf%20viewer?hl=zh_CN

另外,确保您的服务器端代码正确的一种方法是将输出保存为扩展名为.pdf的文件,然后尝试将其打开以确保它是正确的PDF。

如果需要强制Chrome浏览器下载文件而不是查看文件,以便系统PDF查看器可以查看文件。 您可以按照此问题使用标题Content-Disposition: attachment

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM