Loading ...
Sorry, an error occurred while loading the content.

Upload binary attachments on NT

Expand Messages
  • ricon@hotmail.com
    Hi all! I m writing a program that receives files sent to it from a web browser as attachments and saves them on the web server (upload images, pdf docs, etc).
    Message 1 of 1 , Sep 15, 2000
    • 0 Attachment
      Hi all!
      I'm writing a program that receives files sent to it from a web
      browser as attachments and saves them on the web server (upload
      images, pdf docs, etc). The program uses get_form.pl to handle the
      query string. It works grat on Unix, but I'm having problems on NT.
      NT
      doesn't like binary files. They are uploaded on the NT server, but
      they are corrupted (kinda written as ascii, instead of binary).

      I wrote this subroutine to fix the problem:

      # fix corrupted binary files
      sub binIt{
      my ($fto) = @_; # file to open - file name of file to fix
      my $fts = "bin.tmp"; # file to save - new temp file to save
      my ($read, $buffer, $thisMany) = "";
      open(OLDFILE, $fto);
      open(NEWFILE, ">$fts");
      binmode(OLDFILE);
      while ($read = sysread(OLDFILE, $buffer, 4096)) {
      $thisMany += $read;
      print NEWFILE $buffer; # write buffer on new temp file
      }
      close(OLDFILE);
      close(NEWFILE);
      unlink($fto); # delete old file
      rename($fts, $fto); # rename new temp file to file name to fix
      }

      from this one that I found:

      open(NEWFILE, "$newFileName") || die "no way";
      binmode($fileName); ## name of file sent from the browser
      while ($read = sysread($fileName, $buff, 4096)) {
      $thisMany += $read; # this is only for keeping up with byte read
      print NEWFILE $buff;
      }
      close NEWFILE

      but it still doesn't work... Any suggestions? All I need is a script
      to upload binary files sent as attachments from the browser to an NT
      server. Is there a module or anything that I can use to accomplish
      this?

      And now it's time for my standard cry for help:
      Aaaaaaaaaaaaaahhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!

      Thanks for any help in advance!
      Ricon
    Your message has been successfully submitted and would be delivered to recipients shortly.