Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Pdf Attachments To Open Rather Than Download Rate Topic   - - - - -

 
  • Abaco
  • Member
  • Members
  • Join Date: 30-Jan 12
  • 46 posts

Posted 11 March 2015 - 02:56 PM #1

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.

 
  • jimmyod
  • Senior Member
  • Members
  • Join Date: 24-Apr 12
  • 449 posts

Posted 11 March 2015 - 08:44 PM #2

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.

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 12 March 2015 - 09:22 AM #3

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}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Abaco
  • Member
  • Members
  • Join Date: 30-Jan 12
  • 46 posts

Posted 19 January 2016 - 02:46 PM #4

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.  



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 19 January 2016 - 03:13 PM #5

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\"");
}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Abaco
  • Member
  • Members
  • Join Date: 30-Jan 12
  • 46 posts

Posted 20 January 2016 - 06:14 AM #6

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.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 20 January 2016 - 08:31 AM #7

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


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Abaco
  • Member
  • Members
  • Join Date: 30-Jan 12
  • 46 posts

Posted 20 January 2016 - 02:17 PM #8

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.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 20 January 2016 - 03:48 PM #9

You are welcome!


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • 1800db
  • Newbie
  • Members
  • Join Date: 24-Aug 16
  • 12 posts

Posted 25 August 2016 - 02:39 PM #10

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



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 25 August 2016 - 02:42 PM #11

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

 

Thank you for keeping us updated


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • 1800db
  • Newbie
  • Members
  • Join Date: 24-Aug 16
  • 12 posts

Posted 25 August 2016 - 05:30 PM #12

@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
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 26 August 2016 - 10:16 AM #13

@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") {


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • asourmelis
  • Newbie
  • Trial users
  • Join Date: 07-Nov 14
  • 11 posts

Posted 13 October 2016 - 07:33 AM #14

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



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 13 October 2016 - 02:07 PM #15

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}) [<a class="attachment__a cm-no-ajax" href="{"attachments.getfile?attachment_id=`$file.attachment_id`"|fn_url}">{__("download")}</a>]

with

        {$file.description} ({$file.filename}, {$file.filesize|formatfilesize nofilter}) [<a target="_blank" class="attachment__a cm-no-ajax" href="{"attachments.getfile?attachment_id=`$file.attachment_id`"|fn_url}">{__("download")}</a>]

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • asourmelis
  • Newbie
  • Trial users
  • Join Date: 07-Nov 14
  • 11 posts

Posted 14 October 2016 - 06:29 AM #16

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

Is there a way to make it work?



 

Posted 06 May 2017 - 11:49 PM #17

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


Calvin
Small Engine Parts and supplies
Need Parts for Chainsaws ETC? We have them Obsolete Parts For Homelite McCulloch Echo Poulan

 

Posted 18 April 2019 - 02:30 PM #18

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



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19709 posts

Posted 19 April 2019 - 06:30 AM #19

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


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.