Welcome Guest, Not a member yet? Register   Sign In
download remote file with resumable capability
#1

i need to scrip to download remote file with resumable capability . i write this code but notworking true. 
PHP Code:
$CI =& get_instance();
$CI->load->helper('func');
$CI->load->helper('download');
if(
$fileData !== false){
 
   $timeexpire $fileData['time'];
 
   $now time();
 
   $file '';
 
   if($timeexpire $now){
 
       redirect('download/time/2');
 
   }else{
 
       $url              str_replace(" ","%20",$fileData['url']);
 
       $fileinfo pathinfo($url);
 
       $mimType= ($fileinfo['extension'] == 'mp3') ? 'audio/mpeg' 'txt';//set mime type to mp3
 
       $fileSize curl_get_file_size($url);//get file size with curl
 
       $foundCode existfile($url);//check exists file or not and return 400 or 200          
 
       if($foundCode == 200){
 
          $handel        = @fopen($url,'r');
 
       }else{
 
            redirect(base_url().'track/faild'); 
 
                      
        $begin    
1;
 
       $end      $fileSize ;
 
       $fileName basename($url);
 
       if (isset($_SERVER['HTTP_RANGE'])){
 
           if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i'$_SERVER['HTTP_RANGE'], $matches))
 
           {
 
               $begin  intval($matches[1]);
 
               if (!empty($matches[2]))
 
               {
 
                 $end  intval($matches[2]);
 
               }
 
           }
 
       }
 
       if (isset($_SERVER['HTTP_RANGE']))
 
       {
 
         header('HTTP/1.1 206 Partial Content');
 
       }
 
       else
        
{
 
        header('HTTP/1.1 200 OK');
 
       }
 
       header('Pragma: public');     // required
 
       header('Accept-Ranges: bytes'); 
 
       header("Content-Type: $mimType");        
        header
("Content-Disposition: attachment; filename=$fileName");
 
       header('Cache-Control: private');        
        header
("Content-Range: bytes $begin-$end/$fileSize");
 
       header('Content-Length:' $fileSize);        
        $cur  
$begin;
 
       fseek($handel,$cur,0);
 
       if($handel != NULL){                        
            while
(!feof($handel))
 
                                       
                print fread
($handel1024);
 
               //$cur += 1024*16;
 
           }
 
       }else{
 
           redirect(base_url()."track/faild");
 
       }
 
              

Reply


Messages In This Thread
download remote file with resumable capability - by programmer - 06-24-2017, 03:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB