Viewing attachments in browser

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
SS113
Posts: 27
Joined: Mon Aug 15, 2011 1:27 pm

Viewing attachments in browser

Post 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
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: Viewing attachments in browser

Post 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: ");
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
SS113
Posts: 27
Joined: Mon Aug 15, 2011 1:27 pm

Re: Viewing attachments in browser

Post 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']);
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: Viewing attachments in browser

Post 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.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply