I have been able to get uploads of files to work correctly, but I have run into a snage. I am unable to get the data to upload into a (PDF)file. The name gets created but it has a 0 bytes. I changed my HTML to ENCTYPE="application/pdf" from ENCTYPE="multipart/form-data". My CGI looks like the following:
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "<HTML><HEAD><TITLE>Upload Script</TITLE></HEAD><BODY>"; use CGI; # load the CGI.pm module my $GET = new CGI; # create a new object my @VAL = $GET->param; #get all form field names foreach(@VAL){ $FORM{$_} = $GET->param($_); # put all fields and values in hash } $uploadfile = $FORM{'userfile'}; $orgfile = $FORM{'userfile'}; $uploadfile =~ s/^.*(\\|\/)//; $uploadfile =~ s/\s+//ig; $uploadfile =~ s/\./PsJsDoT/g; $uploadfile =~ s/\-/PsJsDaSh/g; if($uploadfile =~ /\W/){ $uploadfile =~ s/\W/n/ig; # replace any bad chars with the letter " +n" } $uploadfile =~ s/PsJsDoT/\./g; $uploadfile =~ s/PsJsDaSh/\-/g; $filesize = $FORM{'MAX_FILE_SIZE'}; $denverfile = "../data/denver/"; $chicagofile = "../data/chicago/"; $lafile = "../data/losangelas/"; $sanfile = "../data/sandiago/"; ($city,$date,$name,$ext) = split(/\./,$uploadfile); if ($city eq "denver") { $movefile = $denverfile.$uploadfile; }elsif ($city eq "chicago") { $movefile = $chicagofile.$uploadfile; }elsif ($city eq "losangelas") { $movefile = $lafile.$uploadfile; }elsif ($city eq "sandiago") { $movefile = $sanfile.$uploadfile; }else{ $newfile = "../data/$city/"; mkdir ("../data/$city", 0777); chmod(0777, "../data/$city"); $movefile = $newfile.$uploadfile; } print "The file you uploaded was: $uploadfile\n"; print "The file went to directory: $movefile\n"; open(NEW, ">$movefile") || die "Can not open $movefile"; binmode NEW; #switch to binary mode # start reading users HD 1 kb at a time. while ($bytesread=read($orgfile, $buffer, 1024)) { # print each kb to the new file on the server print "buffer: ".$buffer; print NEW $buffer; } close NEW; # close the new file on the server and we're don +e chmod(0777, "$movefile"); print "</BODY></HTML>"; exit;
but the $buffer always seems to be empty. Can anyone help. Please email me with ideas: dave@ddsis.net or blanscet_d@hotmail.com Thanks for the time. Dave
edited by boo_radley : code tags

In reply to upload PDF files by dave

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.