Page 1 of 1

Viewing attachments in browser

Posted: Tue Jun 10, 2014 2:52 pm
by SS113
Hello,

I'm trying to not have to download the attachments and view them directly in the browser. I found this viewtopic.php?f=13&t=4827&p=21073#p21064 but it seems it's for an older version because doing that change doesn't seem to affect 2.5.3. I understand the risks involved with doing it this way so I'm ok with that.

Any other ideas?

Thanks

Re: Viewing attachments in browser

Posted: Tue Jun 10, 2014 6:13 pm
by Klemen
Same file and instructions, but instead of

Code: Select all

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
search for

Code: Select all

header("Pragma: ");

Re: Viewing attachments in browser

Posted: Thu Jun 12, 2014 1:24 am
by SS113
Thanks Klemen, that's what I was thinking but it still pops up with a download dialogue.

here's the code that it looks like:

download_attachment.php:

Code: Select all

// Send the file as an attachment to prevent malicious code from executing
$open_directly = array(
'pdf',
'jpg',
'jpeg',
'gif',
'png',
'txt',
);

if ( isset($open_directly[strtolower(pathinfo($file['real_name'], PATHINFO_EXTENSION))]) )
{
   header('Location: ' . $realpath);
    exit();
}

header("Pragma: "); # To fix a bug in IE when running https
header("Cache-Control: "); # To fix a bug in IE when running https
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $file['size']);
header('Content-Disposition: attachment; filename=' . $file['real_name']);

Re: Viewing attachments in browser

Posted: Fri Jun 13, 2014 10:55 am
by Klemen
Thanks code redirects the browser to the file, but what the browser does with that file is up to the browser and not something HESK controls.