title: force to download a remote file via curl or other method
body: <p>I have a remote link from which I want to force download a file. Right now I am using cURL.</p>
  
  <p>My script works for this url (as I tested a different one):
  <a href="http://images.mob.org/iphonegame_img/rip_curl_surfing_game_live_the_search/real/1_rip_curl_surfing_game_live_the_search.jpg" rel="nofollow">http://images.mob.org/iphonegame_img/rip_curl_surfing_game_live_the_search/real/1_rip_curl_surfing_game_live_the_search.jpg</a></p>
  
  <p>But I need it to work on this one:
  <a href="https://googledrive.com/host/0B_3oJnpnNoF9UjlkVUwtWE5CY0U/city.jpg" rel="nofollow">https://googledrive.com/host/0B_3oJnpnNoF9UjlkVUwtWE5CY0U/city.jpg</a></p>
  
  <p>And here is my PHP code</p>
  
  <pre><code> &lt;?php
      $file = 'http://images.mob.org/iphonegame_img/rip_curl_surfing_game_live_the_search/real/1_rip_curl_surfing_game_live_the_search.jpg';
      download($file,2000);
  
      function download($file,$chunks){
          set_time_limit(0);
          header('Content-Description: File Transfer');
          header('Content-Type: application/octet-stream');
          header('Content-disposition: attachment; filename='.basename($file));
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Expires: 0');
          header('Pragma: public');
          $size = get_size($file);
          header('Content-Length: '.$size);
  
          $i = 0;
          while($i&lt;=$size){
              //Output the chunk
              get_chunk($file,(($i==0)?$i:$i+1),((($i+$chunks)&gt;$size)?$size:$i+$chunks));
              $i = ($i+$chunks);
          }
  
      }
  
      //Callback function for CURLOPT_WRITEFUNCTION, This is what prints the chunk
      function chunk($ch, $str) {
          print($str);
          return strlen($str);
      }
  
      //Function to get a range of bytes from the remote file
      function get_chunk($file,$start,$end){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $file);
          curl_setopt($ch, CURLOPT_RANGE, $start.'-'.$end);
          curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
          curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'chunk');
          $result = curl_exec($ch);
          curl_close($ch);
      }
  
      //Get total size of file
      function get_size($url){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_HEADER, true);
          curl_setopt($ch, CURLOPT_NOBODY, true);
          curl_exec($ch);
          $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
          return intval($size);
      }
  
      ?&gt;
  </code></pre>
  
  <p>I don't know what to do know. Please advice something.</p>