file download using header
| From: | Joshua Minnie | Date: | Fri, 23 Jan 2004 14:52:08 +0000 |
| Subject: | file download using header | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-175517@lists.php.net to get a copy of this message | ||
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