简体   繁体   English

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

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

I've the problem. 我有问题。 Here is my code of php: 这是我的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);
        }

        }

This code literally works on windows platform. 该代码从字面上可以在Windows平台上使用。 When I try to run that code on mac, it doesn't work. 当我尝试在Mac上运行该代码时,它不起作用。 I think that code should be worked on all platform instead. 我认为应该改为在所有平台上使用代码。 Becase all this time, I never have found the problem like this. 一直这样,我从来没有发现过这样的问题。 I have the code that working on windows, that code also work on mac. 我有在Windows上运行的代码,在Mac上也可以运行。 Please someone help me for fixing this issue. 请有人帮我解决此问题。

视窗

苹果电脑

There is one post on similar issue 关于类似问题有一篇文章

Well, Chrome is meant to be a basic browser that is customizable to your needs with extensions. 嗯,Chrome应该是一种基本的浏览器,可以通过扩展自定义您的需求。 Our Web App Store features a bunch of free, handy dandy extensions that will let you view PDFs right in your browser. 我们的Web App Store具有许多免费的便捷花色扩展,这些扩展使您可以在浏览器中直接查看PDF。

Please try to install a plugin to view the PDF files in chrome on MacOS 请尝试安装插件以在MacOS上查看Chrome中的PDF文件

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

Also, one way to make sure you have your server side code correct is to save the output as a file with .pdf extension and try to open it to make sure it is a correct PDF. 另外,确保您的服务器端代码正确的一种方法是将输出保存为扩展名为.pdf的文件,然后尝试将其打开以确保它是正确的PDF。

If it is required to force Chrome to download the file instead of viewing it so the file can be viewed by the system PDF viewer. 如果需要强制Chrome浏览器下载文件而不是查看文件,以便系统PDF查看器可以查看文件。 You can use the header Content-Disposition: attachment as per this question . 您可以按照此问题使用标题Content-Disposition: attachment

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

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