title: Downloading large files reliably in PHP
body: <p>I have a php script on a server to send files to recipents: they get a unique link and then they can download large files. Sometimes there is a problem with the transfer and the file is corrupted or never finishes. I am wondering if there is a better way to send large files</p>
  
  <p>Code:</p>
  
  <pre><code>$f = fopen(DOWNLOAD_DIR.$database[$_REQUEST['fid']]['filePath'], 'r');
  while(!feof($f)){
      print fgets($f, 1024);
  }
  fclose($f);
  </code></pre>
  
  <p>I have seen functions such as</p>
  
  <pre><code>http_send_file
  http_send_data
  </code></pre>
  
  <p>But I am not sure if they will work.</p>
  
  <p>What is the best way to solve this problem?</p>
  
  <p>Regards<br>
  erwing</p>