Re: Re: IE download problem
| From: | Curt Zirzow | Date: | Thu, 27 Nov 2003 08:51:02 +0000 |
| Subject: | Re: Re: IE download problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171176@lists.php.net to get a copy of this message | ||
* Thus wrote pete M (pmorgan@ukds.net):
> thsi si a nighmare area..... and loast days on same problem
Its a nightmare area cause so many things can go wrong with your
script.
>
> This works for me.. hope it does for you
>
> $file = $_GET['file'];
> $path = '/www/cgi-bin/docu/personal/'.$file;
very insecure, no de-tainting of the string or ensuring the file
isn't accessing bad things ie:
?file=../../../../etc/passwd
> //force download dialog
> header("Content-type: application/octet-stream\n");
New lines are ignore and stripped so its unneeded, besides that
http headers should have \r\n.
> header("Content-disposition: attachment; filename=\"$file\"\n");
> header("Content-transfer-encoding: binary\n");
> header("Content-length: " . filesize($path) . "\n");
$path was never checked for existance, you'll confuse the client by
sending a wrong content-length.
>
> //send file contents
> $fp=fopen($path, "r");
> fpassthru($fp);
Again $path wasn't checked to see if it was a valid file.
Curt
--
"My PHP key is worn out"
PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/