title: Downloading File via php script
body: <p>I just switched from 000webhost(free) to godaddy(paid) servers and so far, it's like 10x worse than 000webhost >.></p>
  
  <p>Anyways, my problem is with the downloads. I use the following code and it worked fine on 000webhost to allow users to download rar files but now on godaddy, the rar file would return a end of archive error. I checked via FTP, the files are have not been corrupted via upload</p>
  
  <pre><code>&lt;?php
  $userAgent = $_SERVER['HTTP_USER_AGENT'];
  $IP1 = $_SERVER['HTTP_X_FORWARDED_FOR'];
  $IP2 = $_SERVER['REMOTE_ADDR'];
  $HWID = $_GET['HWID'];
  date_default_timezone_set('America/New_York');
  $date = date("m/d/y g:i:sA", time());
  $file = $_GET['file'];
  
  file_put_contents('Logs/Downloaded.txt', "IP: " . $IP2 . " Downloaded On: " . $date . " File: " . $file . " User Agent: " . $userAgent . "\n", FILE_APPEND);
  
  
  
  $path = "files/";
  $fullPath = $path.$file;
  
  if(file_exists($fullPath)){
  if ($fd = fopen ($fullPath, "r")) {
      $fsize = filesize($fullPath);
      $path_parts = pathinfo($fullPath);
      $ext = strtolower($path_parts["extension"]);
      switch ($ext) {
          case "pdf":
          header("Content-type: application/pdf"); // add here more headers for diff. extensions
          break;
          case "zip":
          header("Content-type: application/zip");
      break;
          default;
          header("Content-type: application/octet-stream");
      }
      header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
      header("Content-length: $fsize");
      header("Cache-control: private"); //use this to open files directly
      while(!feof($fd)) {
          $buffer = fread($fd, 2048);
          echo $buffer;
      ob_flush();
          flush(); 
      }
  }
  fclose ($fd);
  exit;
  }else{
      die("File could not be found");
  }
  ?&gt;
  </code></pre>