----- Original Message ----
> From: Tommy Pham <[email protected]>
> To: [email protected]
> Sent: Thursday, September 24, 2009 4:19:48 PM
> Subject: Re: [PHP] Downloader help needed :-(
>
> ----- Original Message ----
>
> > From: Chris Payne
> > To: [email protected]
> > Sent: Thursday, September 24, 2009 2:57:57 PM
> > Subject: [PHP] Downloader help needed :-(
> >
> > HI everyone,
> >
> > Thanks for those of you in the past that helped me with my downloader
> > not displaying the filename. Someone gave me a link to the downloader
> > below which works GREAT but i've tried and tried to limit the data
> > transfer to 60KB a second andI can't get it to work, can any of you
> > see what I could add to get it to work? The first peice of code the
> > code I WANT to use as it lets me download with the correct filename
> > etc ...... but the second piece of code allows me to limit the speed
> > of the transfer but when I try to merge the second with the first it
> > craps out on me.
> >
> > Any help would REALLY be appreciated on this one.
> >
> > Thanks everyone.
> >
> > Piece of code 1 (Code I WANT to use)
> >
> > function forceDownload($file) {
> > /**
> > * Function forceDownload:
> > * download any type of file if it exists and is readable
> > * -------------------------------------
> > * @author Andrea Giammarchi
> > * @date 18/01/2005 [17/05/2006]
> > * @compatibility PHP >= 4.3.0
> > */
> > if(file_exists($file) && is_readable($file)) {
> > $filename = basename($file);
> > if(strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MSIE') !== false
> > && strpos($filename, '.') !== false) {
> > $parsename = explode('.', $filename);
> > $last = count($parsename) - 1;
> > $filename = implode('%2E', array_slice($parsename, 0, $last));
> > $filename .= '.'.$parsename[$last];
> > };
> > header('Content-Type: application/octet-stream');
> > header('Content-Disposition: attachment; filename="'.$filename.'"');
> > header('Content-Length:'.filesize($file));
> > header('Content-Transfer-Encoding: binary');
>
> $speed = 60; // i.e. 60 kb/s download rate
>
> > if(@$file = fopen($file, "rb")) {
> > while(!feof($file))
> {
> // echo fread($file, 8192);
> echo fread($fd, round($speed*1024)); // $speed kb at a time
Sorry, still not wide awake from my afternoon nap...
The above should read:
echo fread($file, round($speed*1024)); // $speed kb at a time
> flush();
> sleep(1);
> }
> fclose($file);
>
> > };
>
>
> > exit(0);
> > };
> >
> > };
> >
> > Piece of code 2 (Which limits nice but has other issues)
> >
> > $speed = 60; // i.e. 60 kb/s download rate
> > if(file_exists($file) && is_file($file)) {
> > header("Cache-control: private");
> > header("Content-Type: application/octet-stream");
> > header("Content-Length: ".filesize($file));
> > //header("Content-Disposition: filename=$file" . "%20");
> >
> > header("Content-Disposition: attachment; filename=\"$file\"");
> >
> > flush();
> > $fd = fopen($file, "r");
> > while(!feof($fd)) {
> > echo fread($fd, round($speed*1024)); // $speed kb at a time
> > flush();
> > sleep(1);
> > }
> > fclose ($fd);
> > }
> >
> > Thank you everyone, it's really appreciated.
> >
> > Chris
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Try the above changes.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php