I am using CGI to accept an upload from windows machine and write a cab file on my linux server. I then try to use cabextract to open the saved cab file but it says that the uploaded cab file has "2 Extra bytes at end of file". Does anyone have a script to remove extra bytes at end of a file? or does anyone know how to solve this problem?
#!/usr/bin/perl #use strict; use CGI qw/:standard/; use Digest::MD5 qw(md5 md5_hex md5_base64); print header(); my $file = param('file'); if (!$file) { #file does not exist print "Error: No file to upload"; return; } #Ignore all but cab files my $fname=$file; if($fname !~/\.cab$/is){ print "Error: Not a cab file"; return; } my $time=time(); my $data=''; while (<$file>) { $data .= $_; } my $md5=md5_hex($data); my $filename="ufiles/$md5\_" . $fname; if(open(FH,">$filename")){ binmode(FH); print FH $data; close(FH); #print the MD5 hash as a return value on success print $md5; } else{ print "Failed to upload file"; }

-------------------------------
Perl - Regularly Expression yourlself
http://www.basgetti.com


In reply to Remove Extra bytes at end of file by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.