Re: If statements inside PHP Curl Writefunction
Jake Cattrall <[email protected]> Mon, 6 Aug 2012 16:33:50 +0100
| Newsgroups | gmane.comp.web.curl.php |
|---|---|
| Message-ID | <CAE6E-mAoSucvYBBr2c9Rqj7L6N=fE4H1DS4iqCVovtHLvj=6MA@mail.gmail.com> |
Thanks that did help, it is now calculating all the way to the end, however there is some strange math going on here. I downloaded a 300mb file and the reported size is 500mb? I've tried this various ways now, calculating results as bits and bytes and it refuses to come out correct. I'm gonna cut my losses and presume this functionality is not available in curl. Instead I will calculate how much a user has downloaded by adding it all up after the server has finished downloading the file. Thanks. On 6 August 2012 11:10, <[email protected]> wrote: > On 05/08/12 19:43, Jake Cattrall wrote: > >> >> curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $chunk) { >> $chunksize = strlen($chunk); >> $downloaded .= $chunksize; >> > > I think you need to declare $downloaded as static, initialise it, and > then $downloaded += $chunksize; > > With ".=" it's doing a string concatenation. > > > if($downloaded > $milestone){ >> echo "milestone"; >> $downloaded = 0; >> > > $downloaded -= $milestone; > ______________________________**_________________ > http://cool.haxx.se/cgi-bin/**mailman/listinfo/curl-and-php<http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php> > _______________________________________________ http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php