I am trying to force a file download using headers.  The problem is not
forcing the download.  That is working fine, but if the user wants to click
on another download while the first one is still downloading it won't let
the user do it.

Here is the code that I'm using, adapted from phpbuilder.com:

<?php
    $pathtofile = '\abs\path\to\file\'.urldecode( $_GET['link'] );
    $download = 'http://www.somewhere.com'.urldecode( $_GET['link'] );
    $type = urldecode( $_GET['type'] );
    $size = filesize( $pathtofile );
    header("Pragma: private");
    header("Expires: 0"); // set expiration time
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    // browser must download file from server instead of cache

    // force download dialog
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Type: $type");

    // use the Content-Disposition header to supply a recommended filename
and
    // force the browser to display the save dialog.
    header("Content-Disposition: attachment;
filename=".basename($download).";");

    /*
    The Content-transfer-encoding header should be binary, since the file
will be read
    directly from the disk and the raw bytes passed to the downloading
computer.
    The Content-length header is useful to set for downloads. The browser
will be able to
    show a progress meter as a file downloads. The content-lenght can be
determines by
    filesize function returns the size of a file.
    */
    header("Content-Transfer-Encoding: binary");
    header("Accept-Ranges: bytes");
    header("Content-Length: $size");

    $fh = fopen( $pathtofile , "rb");
    fpassthru($fh);
    fclose($fh);
?>
[after this the html content is displayed]

Does anybody have any idea to allow for multiple downloads while another one
was going on.  Maybe some additional headers?  I have tried adding headers
before and after where I open the file for HTTP/1.1 200 OK and the
corresponding headers.  I have also tried using a simple meta refresh, but
that doesn't work because it won't refresh until the page is entirely
loaded.

I am at a loss, I can't seem to find answer when I google it either.  Maybe
I'm just missing something.  I don't know.

Josh

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to