user2806026 user2806026 - 4 months ago 22
PHP Question

Download file from absolute path

I am trying to download a file from an absolute path, but I can't get it to work. What am I doing wrong?

$fileurl = '/home/mydomain/public_html/wp-content/uploads/312tekstsecure3.pdf';
header("Content-type:application/pdf");
header('Content-Disposition: attachment; filename=' . $fileurl);
readfile( $fileurl );

Answer
**You need to change just one line.** 
    <?php 
    $fileurl = 'yourpath/file.pdf';
    header("Content-type:application/pdf");
    header('Content-Disposition: attachment; filename=' . $fileurl);
    readfile( $fileurl );
    ?>