MyBB Community Forums

Full Version: Embed document (docx,pdf,txt) attachments in posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there!
I am currently working on a forum for authors. As these guys often share documents as txt, docx and pdf files, I have many open requests to embed such files directly in posts.
Now I looked around a bit and found the excellent Google Docs viewer: https://docs.google.com/viewer.
It renders all common document file formats and has a clean and embeddable UI, you can simply embed an iframe to the file URL in the following syntax:
<iframe seamless="seamless" src="https://docs.google.com/viewer?embedded=true&url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf" width="100%" height="800px"></iframe>

I tried to understand where the attachment.php is making images show up full size in posts and work out a solution from there but wasn't able to find anything seemingly related to this. Then I created a custom page where I tried to point the iframe to an attachment (like /attachment.php?aid=1") but the viewer just the html document with an access denied error message even though I allowed the download of attachments for the group guest.

Can anybody help me with this? I'd be happy to create a plugin afterwards to embed documents as I think it is pretty useful.
What I need is a snippet of code to create a html object with the attachment link for specific file types and an explanation for the access problem.




Thank you so much in advance
Radiergummi
*push*
i dont know if this solution for you will work, but make a copy of attachments.php, open cloned file and edit
$filetype = 'application/force-download'; /* Line: 139 */

And remove:

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "msie") !== false) { /* Line: 146 */
	header("Content-disposition: attachment; filename=\"{$attachment['filename']}\"");
} else  {
	header("Content-disposition: {$disposition}; filename=\"{$attachment['filename']}\"");
}
(2014-05-10, 11:33 AM)metonator Wrote: [ -> ]i dont know if this solution for you will work, but make a copy of attachments.php, open cloned file and edit
$filetype = 'application/force-download'; /* Line: 139 */

And remove:

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "msie") !== false) { /* Line: 146 */
	header("Content-disposition: attachment; filename=\"{$attachment['filename']}\"");
} else  {
	header("Content-disposition: {$disposition}; filename=\"{$attachment['filename']}\"");
}

Thank you for the response, nevertheless this only forces the browser to open a save-as-dialog...

In the mean time I think I found the problem - the "Can download attachments?" setting for the group "guest" is enabled but doesnt have any effect. Why is that?