title: Why is my .zip file corrupted after an HTTP file upload?
body: <p>I'm trying to use a CGI script to accept and save a file from a program that is using an HTTP POST to send a zip file.</p>
  
  <p>In the MIME section of the HTTP header it looks something like this:</p>
  
  <pre><code>Content-Disposition: form-data; name="el_upload_file_0"; filename="BugReport.zip";\r\n
  Content-Type: application/octet-stream\r\n\r\n
  </code></pre>
  
  <p>In my CGI code I'm using this:</p>
  
  <pre><code> use CGI;
   use strict;
   my $cgi = CGI-&gt;new;
   my $upload_file = $cgi-&gt;upload('el_upload_file_0');
   my $time = time;
  
   my $filename = "/tmp/$time.zip";
   open TMP, "&gt;$filename";
   binmode TMP;
   while (&lt;$upload_file&gt;) {
      print TMP $_;
   }
   close TMP;
  </code></pre>
  
  <p>The file that keeps getting saved is somehow getting corrupt and is not a valid zip file.  The HTTP request is being sent by a C# app and it's possible that it might be sending a corrupt zip file, but I doubt it.  Is there anything I can do to troubleshoot further?</p>