Hi,
I've run into a problem when creating a button to download pdf file from custom tab on the product page. While I don't really think place matters, as it probably wouldn't work anywhere.
So I have two questions.
Is it possible to use such simple html to create downloadable files in magento?
Where should I store such files? I used /pub/media/custom folder path but I also tried different one.
You can use any file to create a download button
According to Magento standards, downloads should be saved to /pub/media/custom
Modify the code as described below:
1. Replace the button code from :
<button name="button_download" onclick=" <?php $this->DownloadFile(); ?> ">Click me</button>
to:
<button name="button_download" onclick="myFunction()">Click me</button>
2. You need to add the below code at the end of the file:
<script> function myFunction() { /* practice = your module name,index = controller, index function */ window.location = "<?php echo $this->getUrl('practice/index/index/');?>"; } </script>
3. Create one controller and use the code shown as an example:
<?php class Practice_Attachment_IndexController extends Mage_Core_Controller_Front_Action{ public function index() { $file = 'media/attachment/Doc1.pdf'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } ?>
Before checking the result, clear the cache once.