AnonymousUser Posted June 6, 2013 Share Posted June 6, 2013 (edited) Is it possible to open product attachments in a new window instead of downloading? I tried adding target="_blank" to this line <a href="{$link->getPageLink('attachment', true, NULL, "id_attachment={$attachment.id_attachment}")}">{$attachment.name|escape:'htmlall':'UTF-8'}</a> in product.tpl. It shows up in the code, but doesn't actually work. Is there some other way to do this? Edited July 23, 2013 by AnonymousUser (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted June 7, 2013 Share Posted June 7, 2013 it is likely the method used by the attachment controller that is forcing the content to be downloaded. you would need to ensure the mime type of the attachment is being set properly, and that the client viewing the attachment has an associated program to open the file. what type of file are you attaching? Link to comment Share on other sites More sharing options...
AnonymousUser Posted June 7, 2013 Author Share Posted June 7, 2013 I'm attaching PDFs. All browsers that I can think of have some action associated with opening a PDF, whether it's a prompt to download/open or just open, send to an external program and open, etc. I would like to respect that decision instead of force-downloading, if that makes sense. Is there anyway that you know of to adjust how the controller handles these files? (I know that may be asking much, so if you don't, that's fine.) I'm not sure how to check the MIME type, but I've never had any sort of problem with PDFs on other platforms I've used. If that's relevant, can I get any pointers? Link to comment Share on other sites More sharing options...
bellini13 Posted June 8, 2013 Share Posted June 8, 2013 assuming you are using PS v1.5.4.1, looks like you simply need to change the AttachmentController.php from header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); to header('Content-Disposition: inline; filename="'.utf8_decode($a->file_name).'"'); It would be best to do this as an override. I'm also not sure how this will react to non-PDF attachments, so you best test them before you release them to the public 4 Link to comment Share on other sites More sharing options...
AnonymousUser Posted June 17, 2013 Author Share Posted June 17, 2013 bellini13, thank you very much! That worked perfectly. (Sorry it took so long to respond, I was out of town.) Link to comment Share on other sites More sharing options...
Darussalam Posted February 24, 2016 Share Posted February 24, 2016 Hi, I have Prestashop v.1.6.1.4 and this solution is not working for me in Google Chrome or Firefox (even after clearing Prestashop & even browser cache). It is however only opening files in Microsoft Edge. When I comment out the header line, it tries to download index.php right away. Is there more than this line that must be editied in AttachmentController.php file to make it work? header('Content-Disposition: inline; filename="'.utf8_decode($a->file_name).'"'); Sample page: http://dar-us-salam.com/english-books/biography-history/prophet-muhammad-s/the-sealed-nectar-ar-raheeq-al-makhtum.html Link to comment Share on other sites More sharing options...
bellini13 Posted March 3, 2016 Share Posted March 3, 2016 I have tested this in Firefox, Chrome, IE and Edge and it works properly for me. There are 2 changes to be made.... 1) Change or override the AttachmentController.php so that it uses Content-Disposition inline instead of attachment. This will instruct the browser to show the file contents in a browser window, instead of downloading header('Content-Disposition: inline; filename="'.utf8_decode($a->file_name).'"'); 2) If you want the browser to show it in a new window/tab, then you need to change the anchor to include target="_new". Note: You have to realize however, that the browser cannot show the contents of a file, unless that browser knows how to do that. So if the file attachment is a PDF, then you need to have a PDF reader extension installed in the browser. If the file is a zip file, it has to be downloaded, there is no way to show that in a browser 3 Link to comment Share on other sites More sharing options...
Decho Minkov Posted March 25, 2016 Share Posted March 25, 2016 Hello, On opening the file in a new tab: 2) If you want the browser to show it in a new window / tab, then you need to change the anchor to include target = "_ new". Could you specify which file to be edited. Regards, Decho Minkov Link to comment Share on other sites More sharing options...
skansa Posted March 30, 2016 Share Posted March 30, 2016 Hello, On opening the file in a new tab: 2) If you want the browser to show it in a new window / tab, then you need to change the anchor to include target = "_ new". Could you specify which file to be edited. Regards, Decho Minkov I need an help too! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now