Nothing guarantees that it will be viewed, even if you force via .htaccess
all documents of the type docx
using this:
<FilesMatch "\.(?i)(doc|doc|xls|xlsx)$">
Header set Content-Disposition "inline"
</FilesMatch>
Just make sure you informed him that you want inline
, but if the user defaults to browser "his" to download this type, then you have no control over it, after all it has no sense to control the client’s machine, it decides what it wants to do with the HTTP download (I speak download the HTTP response, not to download the file to a folder).
Something else very important, the browser does not view stand-alone Office files, who does this are third party plugins, so some office program install plugins in your browser, formerly browsers did not prevent this, but today browsers are smarter, soon if a program like Msoffice tries to install a plugin/add-on/extension in the user’s browser it is quite capable of this being blocked.
Sometimes the browser detects things like office and can do the "bind" between browser and office, but this is not the rule and is not the obligation of the browser, some do it simply for convenience.
So to summarize, even if the user has Office installed on his PC does not mean that the browser will be able to read the document on the screen, which causes the direct download, since files not recognized by the browser are always downloaded.
So even if you remove the attribute download
the tag <a></a>
and try to adjust the Content-Disposition: inline
with htaccess nothing will guarantee that your users will be able to view.
What is the alternative solution? You (hypothetically) ask me.
The answer is, use a format supported by various browsers and operating systems, including even cell phones tablets, and this format is the:
PDF - Portable Document Format
Note that PDF will work in most browsers and mobile phones, since seven o Content-Disposition: inline
, something like:
<FilesMatch "\.(?i)(pdf)$">
Header set Content-Disposition "inline"
</FilesMatch>
But this is only because fortunately modern browsers see with built-in PDF reader, if it is a very alternative browser or is an older browser then it is likely that it does not view, in the case of Firefox, Edge and Chrome, all have built-in PDF viewer.
@Samuelverissimo ver este https://answall.com/a/100798/3635
– Guilherme Nascimento
@Samuelverissimo If Poser is difficult for you try this https://answall.com/a/176004/3635 - the Iframes part, so you don’t need to convert, but I don’t know if these services are available. Create a new php page, put it in the URL like this
ver.php?documento=http://meusite.com/local/doc.docx
(is an example) E in the view.php content puts:<iframe src="https://view.officeapps.live.com/op/embed.aspx?src=<?php echo urlencode($_GET['document']); ?>"></iframe>
– Guilherme Nascimento
If it doesn’t work try this:
<iframe src="http://docs.google.com/gview?url=<?php echo urlencode($_GET['document']); ?>&embedded=true"></iframe>
– Guilherme Nascimento
@Samuelverissimo the chat takes to get the messages in the Inbox, only comes fast if it is open. I will delete the messages above.
– Guilherme Nascimento