t3oot2a Posted March 16, 2014 Share Posted March 16, 2014 (edited) Hello Some of my products have a pdf file attached. The pdf file appears in "Download" tab on product page. When I click on the pdf link, it appears a save window from browser. I need to open the pdf file in a new tab in browser. Not to download the pdf file. I set in product.tpl target="_blank" but nothing change <li><a target="_blank" href="{$link->getPageLink('attachment', true, NULL, "id_attachment={$attachment.id_attachment}")|escape:'html'}">{$attachment.name|escape:'htmlall':'UTF-8'}</a><br />{$attachment.description|escape:'htmlall':'UTF-8'}</li> My browser has adobe acrobat plugin installed. On other web pages, pdf files open in new tab. I took a look in contollers->front-> AttachmentController.php but I didn't see anything about opening pdf files in a new tab. Edited March 16, 2014 by t3oot2a (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 16, 2014 Share Posted March 16, 2014 controllers/front/AttachmentControlller.php modify this: class AttachmentControllerCore extends FrontController { public function postProcess() { $a = new Attachment(Tools::getValue('id_attachment'), $this->context->language->id); if (!$a->id) Tools::redirect('index.php'); if (ob_get_level() && ob_get_length() > 0) ob_end_clean(); header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$a->mime); header('Content-Length: '.filesize(_PS_DOWNLOAD_DIR_.$a->file)); header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); readfile(_PS_DOWNLOAD_DIR_.$a->file); exit; } } to: class AttachmentControllerCore extends FrontController { public function postProcess() { $a = new Attachment(Tools::getValue('id_attachment'), $this->context->language->id); if (!$a->id) Tools::redirect('index.php'); if (ob_get_level() && ob_get_length() > 0) ob_end_clean(); header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$a->mime); header('Content-Length: '.filesize(_PS_DOWNLOAD_DIR_.$a->file)); //header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); readfile(_PS_DOWNLOAD_DIR_.$a->file); exit; } } i just commented out this line: //header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); Link to comment Share on other sites More sharing options...
t3oot2a Posted March 16, 2014 Author Share Posted March 16, 2014 (edited) controllers/front/AttachmentControlller.php modify this: class AttachmentControllerCore extends FrontController { public function postProcess() { $a = new Attachment(Tools::getValue('id_attachment'), $this->context->language->id); if (!$a->id) Tools::redirect('index.php'); if (ob_get_level() && ob_get_length() > 0) ob_end_clean(); header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$a->mime); header('Content-Length: '.filesize(_PS_DOWNLOAD_DIR_.$a->file)); header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); readfile(_PS_DOWNLOAD_DIR_.$a->file); exit; } } to: class AttachmentControllerCore extends FrontController { public function postProcess() { $a = new Attachment(Tools::getValue('id_attachment'), $this->context->language->id); if (!$a->id) Tools::redirect('index.php'); if (ob_get_level() && ob_get_length() > 0) ob_end_clean(); header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$a->mime); header('Content-Length: '.filesize(_PS_DOWNLOAD_DIR_.$a->file)); //header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); readfile(_PS_DOWNLOAD_DIR_.$a->file); exit; } } i just commented out this line: //header('Content-Disposition: attachment; filename="'.utf8_decode($a->file_name).'"'); thanks, but now the browser get a dialog with open index file. After I chose open, the new tab with pdf file is showed Edited March 16, 2014 by t3oot2a (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 16, 2014 Share Posted March 16, 2014 what prestashop version you use? i modified this code for 1.5.6.2 and it works, i see pdf files in webbrowser window Link to comment Share on other sites More sharing options...
t3oot2a Posted March 17, 2014 Author Share Posted March 17, 2014 I use prestashop 1.5.6.2. I didn't modify anything else. I deleted target="_blank" from product.tpl too. <li><a href="{$link->getPageLink('attachment', true, NULL, "id_attachment={$attachment.id_attachment}")|escape:'html'}">{$attachment.name|escape:'htmlall':'UTF-8'}</a><br />{$attachment.description|escape:'htmlall':'UTF-8'}</li> Link to comment Share on other sites More sharing options...
t3oot2a Posted March 17, 2014 Author Share Posted March 17, 2014 I tried to find what's wrong but I didn't find anything...what can I do? Link to comment Share on other sites More sharing options...
vekia Posted March 17, 2014 Share Posted March 17, 2014 what browser you use? i tried this in chrome can you also try on different browsers? Link to comment Share on other sites More sharing options...
t3oot2a Posted March 17, 2014 Author Share Posted March 17, 2014 Same problem in chrome, firefox, ie, safari. I checked on another pc too. Link to comment Share on other sites More sharing options...
t3oot2a Posted March 25, 2014 Author Share Posted March 25, 2014 please help me to solve this...i really need to open pdfs in a new tab... Link to comment Share on other sites More sharing options...
trevorgilligan Posted October 6, 2015 Share Posted October 6, 2015 doesnt work for me either. i suppose at a basic level it should just be an <a href link> to the document but i dont know how or where to change that! Link to comment Share on other sites More sharing options...
Recommended Posts