title: PHP function to download and overwrite the previews downloaded file
body: <p>I am using the following code to download an archived csv file and uncompress it:</p>
  
  <pre><code>$url="http://www.some.zip";
  $target = 'data-' . md5(microtime()) . '.zip';
  
  function download($src, $dst) {
          $f = fopen($src, 'rb');
          $o = fopen($dst, 'wb');
          while (!feof($f)) {
              if (fwrite($o, fread($f, 2048)) === FALSE) {
                     return 1;
              }
          }
          fclose($f);
          fclose($o);
          return 0;
  }
  
  download($url,$target);
  
  if ( file_exists($target) ){
      echo "Download Successuful &lt;br /&gt;";
      $arc = new ZipArchive;
      if (true !== $arc-&gt;open($target)) {
          echo "Unzipping Failed &lt;br /&gt;";
      }else {
          file_put_contents($out, $arc-&gt;getFromIndex(0));
          echo "Unzipping Successuful &lt;br /&gt;";
          fclose($handle);
      }
  }else {
       echo "Download Failed &lt;br /&gt;";
  }
  </code></pre>
  
  <p>However, on a second run, it does't do anything and I would like to overwrite the initial file with the newer file. (the CSV File)</p>
  
  <p>How should I do that? The solution should take about the same time as the first download!</p>