Re: Download Script
| From: | Jasper Howard | Date: | Fri, 27 Aug 2004 19:10:21 +0000 |
| Subject: | Re: Download Script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194958@lists.php.net to get a copy of this message | ||
When I created a download script a couple weeks ago I used
readfile($filename) instead of fread() and didn't get anything like what
you're getting.
[snippet]
header("Content-type: $type");
header('Content-Disposition: attachment; filename="'.$file_name.'"');
readfile($dfile);
[/snippet]
NOTE: $dfile = path + file;
--
-------------------------------------------------------------->>
Jasper Howard :: Database Administration
Velocity7
1.530.470.9292
http://www.Velocity7.com/
<<--------------------------------------------------------------
"Aaron Todd" <aaloki88@hotmail.com> wrote in message
news:20040827183521.23415.qmail@pb1.pair.com...
> I've created a download script that works quite nicely. The only issue
with
> it is that when I download a file where the file name is like "filename
> v1.0.2.1.exe" there is some extra characters added into the name when it
is
> downloaded. So that file will be "filename v1[1].0.2.1.exe". I am
> wondering if this is my headers that are doing this, but I really dont
know.
>
> Here is my code:
> <?php
> $file = $_GET['file'];
> $path = $_GET['type'];
> $rootpath = "/home/virtual/site341/fst/var/www/downloads/";
> $filename = "$rootpath$path/$file";
> if (file_exists($filename)) {
> header("Content-Description: File Transfer");
> header("Pragma: no-cache");
> header("Content-Type: application/force-download");
> header("Content-Disposition: attachment;
filename=".basename($filename));
> header("Content-Length: ".filesize($filename));
> $handle = fopen(($filename), "r");
> print(fread($handle, filesize($filename)));
> flush();
> fclose($handle);
> } else {
> header("HTTP/1.0 404 Not Found");
> }
> ?>
> If anyone can let me know what is going on I'd appreciate it.
>
> Thanks,
>
> Aaron