title: PHP upload file and read line by line
body: <p>I've got a really bizarre problem here. I'm using the code below to upload a txt file to my server via php.</p>
  
  <pre><code>    &lt;form enctype="multipart/form-data" action="index.php" method="POST"&gt;
          &lt;input type="file" name="uploadfile"&gt;
          &lt;button&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>After uploading the file (which works fine) I convert the contents into an array via the following code:</p>
  
  <pre><code>$fp = @fopen($file, 'r'); 
  
  if ($fp) { 
      $domains = explode("\n", fread($fp, filesize($file))); 
  }
  </code></pre>
  
  <p>Then I run a preg_match to filter down the array:</p>
  
  <pre><code>$list = preg_grep('/^[a-z]+\.com$/', $domains);
  </code></pre>
  
  <p>I confirmed that $domains is getting populated with the data in the txt file, however when I run print_r($list) it's only returning "array( )"</p>
  
  <p>When I upload the same exact text file with FTP and run print_r($list) it works fine.</p>
  
  <p>I also noticed when I upload the same text file with my FTP client the filesize of "domains.txt" is smaller than when I upload it using my html form. Any idea what's going on here?</p>