Hi, I need some help guys and girls. I am the author of a somewhat popular module called HTTP::File, which one-lines that oft-repeated ritual of storing files uploaded to a website via a form.
Further, by orthogonal use of File::Basename, it performs path extraction from the uploaded file in an architecture independant manner.
However, now a user of my module is having a problem. The raw facts first:
  1. Perl Version 5.60
  2. CGI.pm Version 2.56
  3. HTTP::File Version 3.00
  4. Architecture: Windows NT (dont know what webserver)
  5. When using HTTP::File the following is occurring:
    1. A zero-length file of the correct name and directory shows up on his system... the only problem is its zero-length
    2. The uploaded file shows up in /tmp (c:\temp) as CGItemp39633, with the correct contents.
    3. I am including the source for my upload module below. The only line which is suspect is this one:
      while ($bytesread = read($raw_file,$buffer,1024)) { print O $buffer; }
      The reason it is suspect is that I do not check if the read is defined and thus both undef and 0 return values will end the loop.
      If you can suggest a means of improving this one line, I will appreciate it. Source code for HTTP::File follows:
      #!/usr/bin/perl use HTTP::Headers::UserAgent; use File::Basename; $VERSION = '3.0'; package HTTP::File; sub platform { $__platform = HTTP::Headers::UserAgent::GetPlatform ($ENV{HTTP_USE +R_AGENT}); $__platform =~ /^Win/ && return 'MSWin32'; $__platform =~ /^MAC/ && return 'MacOS'; $__platform =~ /x$/ && return ''; } sub upload { ($raw_file, $path,)=@_; # warn " ** raw_file $raw_file\n"; $path = $path ? $path : '/tmp'; # warn " ** path $path\n"; $platform = platform; # warn " ** platform $platform\n"; File::Basename::fileparse_set_fstype(platform); ($basename,$junk,$junk) = File::Basename::fileparse $raw_file; # warn " ** basename $basename\n"; open O, ">$path/$basename" || die $!; while ($bytesread = read($raw_file,$buffer,1024)) { print O $buffer; } close O; return $basename; } 1;

      In reply to Windows NT CGI File Upload Problem by princepawn

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



    4. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
    5. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
    6. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
    7. Please read these before you post! —
    8. 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
    9. 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;
    10. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
    11. See Writeup Formatting Tips and other pages linked from there for more info.