Pdf Attachments To Open Rather Than Download

On our product pages we have an Attachment tab that includes product manuals, spec sheets and other information in a PDF file format. CS-Cart wants to set the link up as a download link. We would prefer that it open the PDF in the browser being used, on a new page, instead of wanting to download the file to the users computer. Is there someway to change these links so that they open in a browser?



Thanks.



CS-Cart Ver 4.2.4 - but did the same thing in previous versions.

I think that may be up to how the customers browser is set up.

I use Chrome and I have my settings so that it will automatically open pdf's.

Open the app/fucntions/fn.fs.php file and replace:



header("Content-disposition: attachment; filename=\"$filename\"");




with



{if fn_get_mime_content_type($filepath) == "application/pdf"}
header("Content-disposition: inline; filename=\"$filename\"");
{else}
header("Content-disposition: attachment; filename=\"$filename\"");
{/if}

Hi eComLabs,

Thank you for responding to my question back in March 2015. I got distracted with other work related issues and did not get the opportunity to follow up on this issue until today. I made the replacement you suggest above, but our site immediately stop working and gave a 500 server error code.

Since I made the original request we have upgraded to 4.3.5. Should this mod work with 4.3.5 as it might have with 4.2.4?

Thank you in advance for taking a second look at this question.

Thank you for the message. Please try the following code:

if (fn_get_mime_content_type($filepath) == "application/pdf") {
    header("Content-disposition: inline; filename=\"$filename\"");
} else { 
    header("Content-disposition: attachment; filename=\"$filename\"");
}

Thank you for your quick response.

The good news is that I made the new changes and the site kept working and did not show an error. Unfortunately, using Chrome, when clicking on an attachment it only wanted to allow the file to be downloaded.

The following code has just been tested on 4.2.4:

if (fn_get_mime_content_type($filepath) == "application/pdf" || fn_get_mime_content_type($filepath) == "application/octet-stream") {
    header("Content-disposition: inline; filename=\"$filename\"");
} else { 
    header("Content-disposition: attachment; filename=\"$filename\"");
}

Hope this will help

Thank you eComLabs!!

That code did the trick. The PDF attachments are now opening within the browser rather than that being setup to download. Exactly what I was after as a solution. It is working in 4.3.5.

You are welcome!

@eComLabs - I just used the code you recommended and it works great on 4.3.9 -ty

@eComLabs - I just used the code you recommended and it works great on 4.3.9 -ty

Thank you for keeping us updated

@eComLabs - this could just be a coincidence but I just did a product export and rather than downloading the file, as it usually does, it opened it up in my browser. Not really a big deal, it was easy to paste it into a spreadsheet, but I thought I would point that out.

@eComLabs - this could just be a coincidence but I just did a product export and rather than downloading the file, as it usually does, it opened it up in my browser. Not really a big deal, it was easy to paste it into a spreadsheet, but I thought I would point that out.

Try to replace:

if (fn_get_mime_content_type($filepath) == "application/pdf" || fn_get_mime_content_type($filepath) == "application/octet-stream") {

with

if (fn_get_mime_content_type($filepath) == "application/pdf") {

Hey there

just wanted to ask something. If i want the file to open in a new tab, what exchactly I must add to that code?

thank you very much

If we talk about attachments tab, please open the following file:

design/themes/THEME/templates/addons/attachments/blocks/product_tabs/attachments.tpl

and replace:

        {$file.description} ({$file.filename}, {$file.filesize|formatfilesize nofilter}) [{__("download")}]

with

        {$file.description} ({$file.filename}, {$file.filesize|formatfilesize nofilter}) [{__("download")}]

The problem is that we have attached the files to the "File" Tab.

Is there a way to make it work?

is there a way to do this same way to open up pdf on the browser itself im using the latest version

Using cs-cart 4.9.3.SP1 and looking to do the same. Need to open in new window. Any suggestions??

In the app/functions/fn.fs.php file change

header('Content-Disposition: attachment; filename="' . $filename . '"');

to

header('Content-Disposition: ' . (AREA == 'C' ? 'inline' : 'attachment') . '; filename="' . $filename . '"');

Then in the design/themes/THEME/templates/addons/attachments/blocks/product_tabs/attachments.tpl file add target="_blank" to links

(!) Not tested