title: How to download a file through my server to the client? PHP
body: <p>There's a file on a server. The file is a ZIP file.</p>
  
  <p>The file has to be downloaded through my server to the client.</p>
  
  <p>I tried using the readfile function but instead of downloading a file it just displays wierd symbols...</p>
  
  <p>I uploaded it here: <a href="http://b-games.co.il/test/download/" rel="nofollow">http://b-games.co.il/test/download/</a></p>
  
  <p>This is the code:</p>
  
  <pre><code>    $file = "2title3.gif";
  if(file_exists($file))
  {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($file));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit;
  }
  </code></pre>
  
  <p>I also tried using this:</p>
  
  <pre><code>$url = 'http://example.com/some.url';
  $src = fopen($url, 'r');
  $dest = fopen('php://output', 'w');
  $bytesCopied = stream_copy_to_stream($src, $dest);
  </code></pre>
  
  <p>But it did the same thing... Just displayd wierd symbols.</p>
  
  <p>What am I doing wrong?
  <a href="http://php.net/manual/en/function.readfile.php" rel="nofollow">http://php.net/manual/en/function.readfile.php</a>
  Here it says it should work...</p>
  
  <p>An important update:</p>
  
  <p>On my localhost the same code works!</p>
  
  <p>Anyone knows why?</p>
  
  <p>Thanks!</p>