繁体   English   中英

在浏览器中使用php显示.msg文件

[英]display .msg file in browser using php

我已经在PHP应用程序中附加了Outlook msg文件。 我将该文件存储在sql服务器数据库中。

现在,我想从浏览器中打开并显示它。

我尝试了这段代码:

  if($ext=="msg")
  {
    header('ContentType : application/octet-stream');
    header('Content-Disposition: attachment; filename='. basename($filename));
    echo base64_decode($file);
  }

$ filename和$ file来自数据库。

在IE和chrome中,它会在Outlook中打开msg文件,但在firefox中不会打开它。

有什么方法可以使其在所有浏览器中正常工作吗?

还是我在某个地方出错或浏览器中有任何设置吗?

我遇到了几乎类似的情况,并且能够解决它。 包括下面的标题,它应该可以正常工作。

问候

header("Pragma: public");
header("Expires: 0");
header('Content-Encoding: UTF-8');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: application/vnd.ms-outlook;charset=UTF-8"); 
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=test.msg");
header("Content-Transfer-Encoding: binary ");
if($ext=="msg")
  {
    header("Content-Type: text/Calendar");
    header('Content-Disposition: inline; filename='. basename($filename));
    echo base64_decode($file);
  }

#composer require hfig/mapi
# needed if you want to convert to MIME format
#composer require swiftmailer/swiftmailer

require 'vendor/autoload.php';

use Hfig\MAPI;
use Hfig\MAPI\OLE\Pear;

$decodelocation = '/var/html/tmp/';
$baseurl = 'http://example.com/tmp/';
$uniquefolder = uniqid();
// message parsing and file IO are kept separate
$messageFactory = new MAPI\MapiMessageFactory();
$documentFactory = new Pear\DocumentFactory();

$ole = $documentFactory->createFromFile('source-file.msg');
$message = $messageFactory->parseMessage($ole);

$html = preg_replace_callback($this->regex, "utf8replacer", $message->getBodyHTML());

if (count($message->getAttachments()) > 0) {
foreach ($message->getAttachments() as $attach) {
    $filename = $attach->getFilename();
    $temploc = $decodelocation . '/' . $uniquefolder . '/' . $filename;
    $fileurl = $baseurl . '/' . $uniquefolder . '/' . $filename;
    $replace_string = get_string_between($html, 'cid:' . $filename, '"');
    if ($replace_string) {
        file_put_contents($temploc, $attach->getData());
        $html = str_replace('cid:' . $filename . $replace_string, base_url($temploc), $html);
    } else {
        $geturl = array(
            'filename' => $filename,
            'path' => cencode($temploc),
        );
        $attachments[] = '<a target="_blank" href="' . $fileurl . '">' . $filename . '</a>';
        }
    }
}
foreach ($message->getRecipients() as $recipient) {
    $email = $recipient->getEmail();
    $name = $recipient->getName();
    if ($recipient->getType() == 'From') {
        $From[] = ($name) ? '<a href="mailto:' . $email . '">' . $name . '</a>' : '<a href="mailto:' . $email . '">' . $email . '</a>';
    } elseif ($recipient->getType() == 'To') {
        $To[] = ($name) ? '<a href="mailto:' . $email . '">' . $name . '</a>' : '<a href="mailto:' . $email . '">' . $email . '</a>';
    } elseif ($recipient->getType() == 'Cc') {
        $Cc[] = ($name) ? '<a href="mailto:' . $email . '">' . $name . '</a>' : '<a href="mailto:' . $email . '">' . $email . '</a>';
    } elseif ($recipient->getType() == 'Bcc') {
        $Bcc[] = ($name) ? '<a href="mailto:' . $email . '">' . $name . '</a>' : '<a href="mailto:' . $email . '">' . $email . '</a>';
    }
}
$data = array(
'From' => '<a href="mailto:' . $message->properties['sender_email_address'] . '">' . $message->properties['sender_name'] . '</a>',
'To' => ($To) ? implode('; ', $To) : '',
'Cc' => ($Cc) ? implode('; ', $Cc) : '',
'Bcc' => ($Bcc) ? implode('; ', $Bcc) : '',
'Subject' => $message->properties['subject'],
'hasAttachment' => $message->properties['hasattach'],
'attachments' => ($attachments) ? implode('; ', $attachments) : false,
'html' => $html,
);
#customize your html page using data array. It is take long time for greater than 5 MB.

暂无
暂无

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

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