Hey: I recently was working on modifying an uploading script so it could take multiple files at once, but for some reason, when it "uploads", all it does is create a blank file with the appropriate name in the appropriate directory. Here is my code. Could someone tell me what I'm doing wrong?

PERL CODE:

#!c:\perl\bin\perl.exe $| = 1; #Not sure what it does, but it works :) #starts the cgi.pm mod use CGI qw(:standard); $cgi = new CGI; #get the form data $file1 = $cgi->param('file1'); $file2 = $cgi->param('file2'); $file3 = $cgi->param('file3'); $file4 = $cgi->param('file4'); #directory you want to upload to $dir = "c:/windows/desktop"; push @files, ("$file1","$file2","$file3","$file4"); foreach $file (@files) { #file_type not necessary but can be useful info #if your wanting to limit uploads to a certain #type of file $file_type = $cgi->uploadInfo($file)->{'Content-Type'}; $file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filenam +e $name = $2; #My understanding gets real iffy from here on in #however it does work in the exact format below open(LOCAL, ">$dir/$name") or die $!; #open file undef $bytesread; undef $buffer; # binmode is only necessary on win32 servers but #it won't hurt with unix so might as well leave it binmode LOCAL; while ($bytes = read($file,$buffer,1024)) { $bytesread += $bytes; print LOCAL $buffer; } close($file); close(LOCAL); chmod(0666,"$dir\/$name"); print $cgi->header(); #prints the header stuff #$bytesread holds the value of the size of the #file in bytes. Useful if you want to restrict #size of uploaded files print "Successful Upload<p>File:$file ($file_type, $bytesread bytes)<B +R>\n"; } exit; #exit's script

HTML CODE:

<HTML> <HEAD> <TITLE>Upload a File Through the WWW</TITLE> </HEAD> <BODY BGCOLOR="#FFFFF"> <H1><TT><B>File Upload!</B></TT></H1> <P> To upload a file through the WWW, fill out the form below: <form method="POST" action="upload.cgi" ENCTYPE="multipart/form-data"> + <body bgcolor=black text=black> File: <input type="file" name="file1"><br> File: <input type="file" name="file2"><br> File: <input type="file" name="file3"><br> File: <input type="file" name="file4"><br> <input type="submit" value="UPLOAD"> </form> </BODY> </HTML>

In reply to Uploading Script Errors by Stamp_Guy

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.