• I have some files saved outside the webroot and need to allow posts in WordPress to be able to access the files.

    Following is the location of one of the files:
    /home1/Mathone/TESTS/Test1/index1.html
    I created a download.php file with the following code:

    `<?php
    $path = ‘/home1/Mathone/TESTS/’. $_GET[‘filename’];
    $mm_type=”application/octet-stream”;
    header(“Pragma: public”);
    header(“Expires: 0”);
    header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
    header(“Cache-Control: public”);
    header(“Content-Description: File Transfer”);
    header(“Content-Type: ” . $mm_type);
    header(“Content-Length: ” .(string)(filesize($path)) );
    header(‘Content-Disposition: attachment; filename=”‘.basename($path).'”‘);
    header(“Content-Transfer-Encoding: binary\n”);
    readfile($path); // outputs the content of the file
    exit();
    ?>

    Next, I created a post in wordpress with the following link:

    download

    I am getting an error

    This is somewhat embarrassing, isn’t it?
    It seems we can’t find what you’re looking for. Perhaps searching can help.
    Can anyone tell me what I am doing wrong? Thanks

  • The topic ‘Accessing a file saved outside webroot in a wordpress post’ is closed to new replies.