Okay, I found a solution to part one of my questions by changing my headers,
but for some reason I am still getting a fractional download of the file.
Most commonly it's about 16.6KB of a 4MB file. The kicker is it says that it
completed successfully.

Here is the modified code:
<?php
    $download = 'url/path/to/file'.urldecode( $_GET['link'] );
    $type = urldecode( $_GET['type'] );
    $size = filesize( '/abs/path/to/file'.urldecode( $_GET['link'] ) );
    header("Pragma: public");
    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");
    // 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("Content-Length: ".(string)($size));
    readfile("$download");
?>

> I am having some trouble making it possible to download a file using the
> header function.  The problems are: (1) I get the dialog box to download
the
> file, but for some reason the type of file isn't getting passed to the
box,
> and (2) when I download a 4MB file it only seems to be getting 16.6KB.
>
> I haven't used header for this purpose before this, so maybe I am missing
> something.  I Googled around and found the content-disposition type I
> thought I needed, I actually tried 3 different types (the file is a
> compressed zip file).  I Googled around for tutorials on downloading files
> and still haven't found the answer to correcting my problem.  Here is the
> code I am using, maybe a couple more trained eyes looking at this could
help
> me out.
>
> <?php
>     $download = 'http://www.usa-financial.com'.urldecode( $_GET['link'] );
>     $type = urldecode( $_GET['type'] );
>     $size = filesize( '/home2/www/usa-financial'.urldecode(
> $_GET['link'] ) );
>     header("Content-type: $type");
>     header("Content-Disposition: attachment; filename=$download;");
>     header("Accept-Ranges: bytes");
>     header("Content-Length: $size");
>
>     echo "<!-- $type \n $size \n $download \n -->\n";
> ?>
>
> Josh

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

Reply via email to