title: PHP download file freezes the computer
body: <p>I want to create a download link, and I found an example online. I forget where I get it.  </p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;?php
  
  // place this code inside a php file and call it f.e. "download.php"
  //$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
  $path = "music/";
  $fullPath = $path.$_GET['download_file'];
  
  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
      //header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
      //break;
      case "mp3":
      header("Content-type: audio/mpeg"); // add here more headers for diff. extensions
      header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
      break;
      case "wma":
      header("Content-type: audio/wma"); // add here more headers for diff. extensions
      header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
      break;
      case "ogg":
      header("Content-type: audio/ogg"); // add here more headers for diff. extensions
      header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
      break;
      default:
      header("Content-type: application/octet-stream");
      header("Content-Disposition: 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;
  }
  fclose ($fd);
  }
  exit;
  // example: place this kind of link into the document where the file download is offered:
  // &lt;a href="download.php?download_file=some_file.pdf"&gt;Download here&lt;/a&gt;
  ?&gt;
  </code></pre>
  
  <p>The problem is when I click the download link, it works. But after few seconds, my whole computer freezes and I need to force a shutdown.  </p>
  
  <p>What is the cause of this problem? Is it my computer fault or the code? I am using WAMP Server 2.</p>
  
  <p>Update : </p>
  
  <p>I tried to use <code>readfile()</code> instead of <code>fread()</code>, however I still get the same problem. Below is my code : </p>
  
  <pre><code>&lt;?php
  $directory_load = simplexml_load_file('conf/configuration.xml');
  $path = $_SERVER['SERVER_ROOT'].$directory_load -&gt; directories;
  echo $path;
  if($_GET['download_file'] != NULL) {
      $fullPath = $path.$_GET['download_file'];
      if (file_exists($fullPath)) {
          header('Content-Description: File Transfer');
          header('Content-Type: application/octet-stream');
          header('Content-Disposition: attachment; filename='.basename($fullPath));
          header('Content-Transfer-Encoding: binary');
          header('Expires: 0');
          header('Cache-Control: must-revalidate');
          header('Pragma: public');
          header('Content-Length: ' . filesize($fullPath));
          ob_clean();
          flush();
          readfile($fullPath);
          exit; 
      }
      else {
          echo "&lt;span style=\"font-size: 15px;\"&gt;The file you requested to download &lt;span style=\"font-size: 30px; font-weight: bold; color: red; padding: 0px 20px;\"&gt;".$_GET['download_file']."&lt;/span&gt; does not exists.&lt;/span&gt;";
      }
  }
  else {
      header("location: index.php");
  }
  ?&gt;
  </code></pre>
  
  <p>UPDATE 2 :</p>
  
  <p>I tested the code with Mozilla version 21.0, it works fine. But as I stated, my computer freeze when I click the download link, it is when I am using Coolnovo (ChromePlus) Version 2.0.8.33. Is it related to the browser?</p>