Keyword

SOLVED! How to always open the attached PDF files directly in the browser?

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98201 by gerardo
I need registered users to attach PDF files to their items. I need then for the download link, on item view, to open those PDF files directly in the browser instead of downloading them.

 

In other words I need for future links' URL to always direct to:

/media/k2/attachments/The_attachment.pdf instead of

/index.php?option=com_k2&Itemid=64&id=7&lang=es&task=download&view=item

 

Is there something I can do through code to change that permanently?

 

Thanks!

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

More
13 years 3 months ago #98202 by BBC
It is personal thing and browsers option. You cannot force users to open PDF like this. I guess.

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

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98203 by gerardo
Are you sure? I find that hard to believe. I really don't know that much about php code but I suppose I could use the code to change the way the K2 attachment links are created, to point to the URL where the file itself is instead of the download command. Know what I mean?

 

Is that really that impossible : ( ?

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

More
13 years 3 months ago #98204 by BBC
You can do it, but you need to have your own PDF viewer script at server. And open PDF wrapped in site.

Don´t know how to do it.

 

I think so anyway. Apologize if i am wrong.

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

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98205 by gerardo
Oh, you're right about that. But I guess I'm ok with the user opening it in their PDF software, just as long as they don't have to download it. Just like you open most PDF files in the web. Know what I mean? A tab in your browser usually opens, like when you use Adobe Reader like me.

 

What I don't like is the download window opening, asking to save or just open the file. That's what I want to avoid. Any ideas?

 

Thanks for all the feedback : )

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

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98206 by gerardo
BBC, do you have any new ideas regarding this? I would really appreciate it.

 

Does anyone else? Thank you!

 

 

 

BBC said:

You can do it, but you need to have your own PDF viewer script at server. And open PDF wrapped in site.

Don´t know how to do it.

 

I think so anyway. Apologize if i am wrong.

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

More
13 years 3 months ago #98207 by BBC
I don´t know. It was just a wild idea.

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

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98208 by gerardo
Thanks BBC.

 

Can anyone PLEASE help me?! I don't think what I'm asking is that complicated. When you upload an attachment through the form, in item's view the download link points to a command to download that file. I want to find a way so does links points to the file itself and not that download command. Know what I mean?

 

I'm not sure in what file would I have to change the code. I think it's not really in form.php. What do you suggest I do?!

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

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98209 by gerardo
Ok, I did it. I'll explain soon how to do it. I hope it'll be helpful in the future for someone else : )

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

  • gerardo
  • gerardo's Avatar Topic Author
  • Visitor
13 years 3 months ago #98210 by gerardo
Ok, here is how I did it. I edited the following file: templates/rhuk_milkyway/html/com_k2/templates/item.php

 

I'm using the rhuk_milkyway template but the folder's name will depend on the template you're using in your site.

Inside the file I looked for this string:

 

<a title="<?php echo htmlentities($attachment->titleAttribute, ENT_QUOTES, 'UTF-8'); ?>" href="<?php echo JRoute::_('index.php?option=com_k2&view=item&task=download&id='.$attachment->id); ?>">                    <?php echo $attachment->title ; ?>

 

You'll find that almost at the end of the second third of the file. And I changed it to:

 

<a title="<?php echo htmlentities($attachment->titleAttribute, ENT_QUOTES, 'UTF-8'); ?>" href="<?php echo JRoute::_('media/k2/attachments/'.$attachment->filename); ?>" TARGET="_blank">                    <?php echo $attachment->title ; ?>

 

I'm using K2's default folder for attachments, but if you changed the folder, you must change the path to point to that particular folder.

 

Thanks to that, whenever someone clicks on an attachment, which in my case they're all PDF files, a second tab opens in the browser showing the PDF file instead of opening the little window asking to download the file =D

 

Hope this is useful : )

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


Powered by Kunena Forum