Search code examples
phpheaderreadfileabsolute-path

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 );

Solution

  • 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 );
    ?>