My contemplations and diurnal novelties are publicized here


Add a download button using following code:-

<a
id=”pdfDownloadLink” target=”_blank” href=”#”><img
src=”<?php
echo
$this->baseUrl(); ?>/images/icon/downloadpdf.png”
/></a>

Use following lines of jquery to change the href attribute on fly:-

$(“#pdfDownloadLink”).attr(‘href’, ‘<?php echo $this->serverUrl() . $this->baseUrl(); ?>/index.php/report/downloadpdf/file/?file=’ + encodeURIComponent(downloadURL));

In Zend the URL follow the following conventions

Index.php/controller/action/param/value/param2/value2/param2/value2…

So providing file url will create problem so I used

/file/?file=FileURL

You also need to add downloadpdf action to your controller

public function downloadpdfAction()   {

$params = $this->getRequest()->getParams();

$this->view->paramfile = $params[‘file’];

 }

And in the view you can simple use following plain php code to download the file

<?php

$file= $this->paramfile;

header (“Content-type: octet/stream”);

header (“Content-disposition: attachment; filename=”.$file.“;”);

header(“Content-Length: “.filesize($file));

readfile($file);

exit;

?>


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: