title: Download a remote file and rename the file- & filetype on client-side
body: <p>I am working on a project where on the client-side it should start a download from a remote URL.</p>
  
  <p>I currently got it to work with cURL, but the problem is that it downloads to the server, and not on the client's browser (asking where to save it).</p>
  
  <p>The URL looks like this:</p>
  
  <pre><code>http://r13---sn-5hn7snee.googlevideo.com/videoplayback?expire=138181&amp;mv=u&amp;ipbits=0&amp;clen=7511717&amp;fexp=929447,913430,930802,916612,902546,937417,913434,936916,934022,936921,936923&amp;ms=au&amp;mt=1396164&amp;itag=247&amp;key=yt5&amp;source=youtube&amp;ip=2a00:7143:100:1:225:90ff:fe52:b3ad&amp;sparams=clen,dur,gir,id,ip,ipbits,itag,lmt,source,upn,expire&amp;signature=DBDCE9EFFC094C0FC653610C8FAAF367EA942CC4C6EF3971A186C&amp;upn=0JQJ6yqyYPo&amp;sver=3&amp;gir=yes&amp;lmt=13960601932&amp;dur=130.133&amp;id=17f0fd8b&amp;size=1280x720,type=video/mp4
  </code></pre>
  
  <p>When downloading this just from the URL the filename will be 'videoplayback' without any file extension. So I need to have a custom file name and .mp4 as file type. (Which works on the cURL code below), but it writes to server instead of client-side download.</p>
  
  <pre><code>function download($file_source, $file_target) {
  $rh = fopen($file_source, 'rb');
  $wh = fopen($file_target, 'w+b');
  if (!$rh || !$wh) {
      return false;
  }
  
  while (!feof($rh)) {
      if (fwrite($wh, fread($rh, 4096)) === FALSE) {
          return false;
      }
      echo ' ';
      flush();
  }
  
  fclose($rh);
  fclose($wh);
  
  return true;
  }
  
  $result = download('http://r13---sn-5hn7snee.googlevideo.com/videoplayback?expire=138181&amp;mv=u&amp;ipbits=0&amp;clen=7511717&amp;fexp=929447,913430,930802,916612,902546,937417,913434,936916,934022,936921,936923&amp;ms=au&amp;mt=1396164&amp;itag=247&amp;key=yt5&amp;source=youtube&amp;ip=2a00:7143:100:1:225:90ff:fe52:b3ad&amp;sparams=clen,dur,gir,id,ip,ipbits,itag,lmt,source,upn,expire&amp;signature=DBDCE9EFFC094C0FC653610C8FAAF367EA942CC4C6EF3971A186C&amp;upn=0JQJ6yqyYPo&amp;sver=3&amp;gir=yes&amp;lmt=13960601932&amp;dur=130.133&amp;id=17f0fd8b&amp;size=1280x720,type=video/mp4');
  
  if (!$result)
       throw new Exception('Download error...');
  </code></pre>
  
  <p>So my question is how I can turn this into so it renames the file and changes the extension to mp4, and then downloads the file on client-side.</p>
  
  <p>Thanks</p>