Forums

Add option for download in WordPress template (2 posts)

  1. pratik60
    Member
    Posted 3 months ago #

    In a template which I've made, I want to add the ability to force a download (so that it gives the user the option to open the file or save the file).

    Now I have linked this page as

    <a href="resumepdf"> </a>

    Now in the resumepdf.php

    <?php
    /*
    Template Name: ResumePdf
    */
    ?>

    and then I have

    <?php
        header('Content-disposition: attachment; filename=resumepdf.pdf');
        header('Content-type: application/pdf');
        readfile("echo bloginfo('template_directory');/about/resume/resumepdf.pdf");
        ?>

    But while the size of the pdf is about 270KB , the size of the downloaded pdf is just 5kb.

    Can someone give me the correct way to force download in the template. Btw to embed pdf this works
    <embed src= "<?php echo bloginfo('template_directory');?>/about/resume/resume.pdf"/>

  2. pratik60
    Member
    Posted 3 months ago #

    I even uploaded the pdf as a media file, and then tried to replace the readfile line as

    readfile("http://precisely.me/wp-content/uploads/2012/02/resumepdf.pdf");

    But even this download a corrupted file with the wrong file size.

Reply

You must log in to post.

About this Topic