download with resume a file using curl
===

Does anyone know how to download a file using curl and PHP and supports resume. and link to a tutorial or code demonstration will be good. I'm using this code now but it doesn't support resume, and i don't know how to handle headers. help will be appreciated

    $start_range = 0; 
    $url = URL to remote file 
    $end_range = $filesize; 
    while($start_range <= $end_range) { 
        if(($start_range + 9999999) > $end_range) $range = $start_range.'-'; 
        else $range = $start_range.'-'.($start_range + 9999999); 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 
        curl_setopt($ch, CURLOPT_REFERER, $refurl); 
        curl_setopt($ch, CURLOPT_RANGE,$range); 
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); 
        curl_exec($ch); 
        curl_close($ch); 
        $start_range +=10000000; 
        flush(); 
            ob_flush() 
    }  