php - How to Create a file download link in a page template -


i need download file on click of link in word press. have file url. know download code in php , added in functions.php.

function downloadfile($f){     header('content-disposition: attachment; filename=' . urlencode($f));     header('content-type: application/force-download');     header('content-type: application/octet-stream');     header('content-type: application/download');     header('content-description: file transfer');     header('content-length: ' . filesize($f));     echo file_get_contents($f); } 

now how call function on click of link? "href" of link

on page link:

<a href="download.php?f=foo">download "foo"</a> 

on download.php (or whatever name choose):

include "functions.php"; downloadfile($_get["f"]); exit; 

edit or create download.php page:

<?php     if(isset($_get["f"])){         $f = $_get["f"];         header('content-disposition: attachment; filename='.urlencode($f));         header('content-type: application/force-download');         header('content-type: application/octet-stream');         header('content-type: application/download');         header('content-description: file transfer');         header('content-length: ' . filesize($f));         echo file_get_contents($f);     }     exit; ?> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -