Jump to content

more_info_tab_attachments - Set PDF open in new tab instead of Download


Recommended Posts

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 by t3oot2a (see edit history)
Link to comment
Share on other sites

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

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

 

post-630188-0-14109000-1394981494_thumb.png

Edited by t3oot2a (see edit history)
Link to comment
Share on other sites

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

  • 1 year later...
×
×
  • Create New...