0

This is one of many functions that I've tried to use to download files from a webpage. The folder is 'files' and I get the file name in the first IF clause, and store the location of it in the 'path' variable. The rest I've copied from online sources, which has positive reviews. I've tried many like this, but they all crash the page.

if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
        $filename = $_GET['file'];
        $path = 'files/' . $filename;
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . basename($path));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($path));
        ob_clean();
        flush();
        readfile($path);
        exit;
}


<div id="downloadWrapper" class="downloadWrapper">
<h1>Download the Mind Booster App</h1>
<hr/>
    <div class="container" style="max-width:780px;">
    <div class="col-md-4">
            <a href="mindbooster.php?file=mindBooster.exe" name="mindBooster"><img src="images/downloadWindows.png" alt="windows"></a>
            </div>
    <div class="col-md-4">
            <a href=""><img  id="androidButton" src="images/play.png" alt="android"></a>

    </div>
    <div class="col-md-4">
            <a href=""><img  id="appleButton" src="images/downloadApple.png" alt="apple"></a>

    </div>
    </div>
</div>
traderjosh
  • 321
  • 5
  • 16
  • I've edited my post. The GET request is successfully received, but something fails with the headers that I've used. – traderjosh Jun 23 '16 at 19:57
  • Yes, the variable 'path' prints files/mindBooster.exe. This program runs just fine if I open it normally. – traderjosh Jun 23 '16 at 20:03
  • I am pretty sure it exists, because it says 'file not found' when I change the path name. This .exe file is a small application. The first error message that is surrounded by the garbage characters says 'this program must be run under Win32'. – traderjosh Jun 23 '16 at 20:26
  • Your browser is not prompting to download the file. Try another browser. – Jose Manuel Abarca Rodríguez Jun 23 '16 at 20:26
  • Same problem in Firefox/Chrome/IE. I'm just curious as to why this is happening. – traderjosh Jun 23 '16 at 20:29
  • It's not happening to me. There is something else. http://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them – Jose Manuel Abarca Rodríguez Jun 23 '16 at 20:35
  • So you think it's to do with my Apache httpd.conf file? Do you know what I need to change? – traderjosh Jun 23 '16 at 21:13
  • http://askubuntu.com/questions/610645/how-to-configure-apache2-to-download-files-directly , http://www.tipsandtricks-hq.com/forum/topic/force-a-file-to-download-instead-of-showing-up-in-the-browser , http://webmasters.stackexchange.com/questions/92581/force-browser-to-put-pdf-or-jpg-links-in-download-queue-instead-of-opening-it – Jose Manuel Abarca Rodríguez Jun 23 '16 at 21:17

0 Answers0