Resident234
@Resident234
Back-End . PHP . Bitrix

Как открыть файл ms word в браузере?

Доброго дня.
Как сделать так, что бы файл ms word открывался на чтение в браузере ?
Вот например код для pdf файла:
$file = 'http://gsu1239m.beget.tech/net_attack.pdf';
$filename = 'net_attack.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile($file);

Файл нормально открывается на чтение.

Для word формата делаю так:
$file = 'http://gsu1239m.beget.tech/wp-content/uploads/2016/12/polost.doc';
$filename = 'polost.doc';
header('Content-type: application/vnd.ms-word');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile($file);

но файл упорно отдаётся на скачивание.
как поступить в случае с вордовским фалом ?

UPD: Решено
:
                                <a target="_blank"
                                   href="http://docs.google.com/viewer?url=http://gsu1239m.beget.tech/wp-content/uploads/2016/12/polost.doc">000000</a>
  • Вопрос задан
  • 3207 просмотров
Решения вопроса 2
@magzhan9292
Если Word у себя на хостинге можешь так

<div url-show="http://docs.google.com/viewer?url=http://amiro.ru/_mod_files/_upload/example.doc&amp;embedded=true" class="show_docs" onclick="showDocs(this); return false;">


<script>
    function showDocs(oLink) {
        var oBlock = oLink.getElementsByTagName('div')[0];
        var oIframe = oLink.getElementsByTagName('iframe')[0];
        var oIframeUrl = oLink.getAttribute('url-show');
        if(oBlock.style.height == 0+'px') {
            oBlock.style.height = 980+'px';
            if(oIframe.src != oIframeUrl) {oIframe.src = oIframeUrl};
        } else {
            oBlock.style.height = 0+'px';
        }
    }
</script>


Источник
Ответ написан
Комментировать
riot26
@riot26
<:З )~~
Pdf открывается для чтения, потому что в браузер вшит ридер на js (https://github.com/mozilla/pdf.js/). Чтобы читать doc, надо гуглить "doc js reader". Второй вариант: лить всё в гугл драйв или офис 365, а потом делать вот так:
<iframe src="http://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc' width='1366px' height='623px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>

источник
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы