Display the PDF file in new tab instead of "SAVE" download prompt.

  • Posts: 5
  • Thank you received: 1
  • Hikashop Business Hikashop Essential
7 years 3 months ago #257970

-- url of the page with the problem -- : palazzetti.ca/shop/bedroom/product/15-na.../category_pathway-46
-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.5
-- Browser(s) name and version -- : Safari
-- Error-message(debug-mod must be tuned on) -- : Display PDF instead of download

Every product in our web site has one or more PDF's. They are uploaded as "files".
We want to click on a PDF and get it automatically to open another tab and display the PDF, rather than having the prompt to SAVE the PDF.

Or, if there is a prompt, we should have a custom one with 3 options: 1) SAVE 2) Open and display in new tab 3) cancel

Does anyone know how to do this?

The following user(s) said Thank You: neimar

Please Log in or Create an account to join the conversation.

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
7 years 3 months ago #257984

Hi,

The Files feature of HikaShop is to allow customers/users to download the files. So of course, it forces the download.
If you want to change that, you'll have to change the content-type header sent by HikaShop.
There are two ways you can do it:
1. You edit the lines:
header('Content-Type: application/octet-stream');
to:
header('Content-Type: application/pdf');
in the file administrator/components/com_hikashop/classes/file.php
It's easy to do, but there are several downsides: You'll loose the change when you update and it won't support other file types properly.
2. You can create a custom Joomla plugin of the group "hikashop" implementing the trigger onBeforeDownloadFile(&$filename, &$do, &$file, $options) in your plugin and sending the file yourself to the user based on the data provided by HikaShop to the trigger function in your plugin. You can read more about creating plugins here:
www.hikashop.com/support/documentation/6...mentation.html#intro

The following user(s) said Thank You: neimar

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
5 years 9 months ago #295121

Hi,

first option not working for me. Hika still downloading file instead of opening pdf in browser.
Can you help me for this problem?

Please Log in or Create an account to join the conversation.

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
5 years 9 months ago #295145

Hi,

Well, I didn't expand on this.
This modification actually doesn't change the way your browser with behave directly.
What this modification changes, is that the browser knows that the file it is downloading is a PDF file instead of a random file.
Knowing that, the browser, based on how you configured it, will download or open the file.
Now, you can also change the line:
header('Content-Disposition: attachment; filename="' . $name . '"');
to:
header('Content-Disposition: inline; filename="' . $name . '"');
in order to ask the browser to try to open the file rather than its default action for the file type you're sending.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 0
5 years 9 months ago #295208

It's working

tnx

Please Log in or Create an account to join the conversation.

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
2 years 4 months ago #337779

Hi,

I tried this but it opens the files in the same window istead of a new.

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
2 years 4 months ago #337781

Hi,

Yes.
The code change I gave before is to open the file in the browser instead of downloading it.
If you want it to be in a new tab, you need to change the line:

$files[] = '<a class="hikashop_product_file_link" href="' .  $file->download_link . '">' . $file->file_name . '</a>';
to:
$files[] = '<a class="hikashop_product_file_link" target="_blank" href="' .  $file->download_link . '">' . $file->file_name . '</a>';
in show_block_product_files.php via the menu Display>Views, supposing that you're also talking about the download links on the product details page.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
1 year 9 months ago #342690

Hi,

After updating to Hikashop 4.6.0 i did the above changes again but now the pdf files look like the are about to open in a new tab but they don't and they just download again.

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
1 year 9 months ago #342693

Hi,

If you did the change as a view override ( www.hikashop.com/forum/product-category-...d-prompt.html#337781 ), you should not need to redo it after the update and it should still work even after the update.
So I'm not clear on the situation.
Can you provide a link to a product page with the issue so that we can check on the situation ?

Please Log in or Create an account to join the conversation.

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
1 year 9 months ago #342695

Hi,

I have an override yes, at every Hikashop update i just rechange the code in the file administrator/components/com_hikashop/classes/file.php and it worked but not this time.

This is a product to check

www.e-develop.gr/el/products/tools-compo...category_pathway-172

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 81476
  • Thank you received: 13059
  • MODERATOR
1 year 9 months ago #342698

Hi,

You made a typo.
You wrote
header('Content-Type: application/pdfm');
instead of
header('Content-Type: application/pdf');

Please double check your modifications.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

Time to create page: 0.094 seconds
Powered by Kunena Forum