A truly supported binary upload, allowing multi-file upload, which can limit the file suffix, generate a complete information. . :)
In fact, after I saw the file of the essence, I felt a bit problem, so I would like to make a better, I would like to thank the brothers who were selflessly dedicated. .
The original upload is not used by binmode methods, so if it is uploaded or binary, it has been resolved now, and you can also upload multiple files. . :) Also added.
Finally, I am a perl newbie, if I have an improper, I hope that my high-end finger is one or two, my life is grateful :)
code show as below:
DEFAULT.HTM:
FILE 1:
FILE 2:
psupload.pl:
# If you use this file with a CGI mode, change the following path to your machine configuration.
#! f: / activeperl / bin / perl
USE CGI;
$ UPFILECUNT = 1;
$ MAXUPLOADCOUNT = 2; # Limit the maximum number of uploaded files
$ basedir = "c: / perltest / perlupload"; # Upload file storage address
$ soall = "no"; # 是 不 限 限 文件 文件 文件 上 上
@Theext = (". zip", ". exe", ". gif"); # 要 要 文件 文件 后 名
Print "Content-Type: Text / HTML / N / N";
While ($ upfilecount <= $ maxUploadcount) {
MY $ REQ = New CGI;
MY $ file = $ req-> param ("File $ upfilecount");
IF ($ FILE NE ") {
MY $ filename = $ file;
$ filename = ~ s /^.* (// | //) //; # with a regular expression to remove the useless path name, get the file name
MY $ newmain = $ filename;
MY $ filenotgood;
IF ($ ALLOWALL NE "YES") {
$ EXTNAME = LC (Substr ($ newmain, length ($ newmain) - 4, 4)); # 取 名
For (My $ I = 0; $ I <@Theext; $ I ) {# This paragraph is detected
IF ($ EXTNAME EQ $ THEEXT [$ I]) {
$ filenotgood = "yes";
Last;
}
}
}
IF ($ filenotgood ne "yes") {# This start to upload
Open (Outfile, "> $ basedir / $ filename");
BINMODE (OUTFILE); # Be sure to use binary, so you can upload binary files. And the text file will not be disturbed
While (My $ BYTESREAD = Read ($ File, MY $ Buffer, 1024)) {
Print Outfile $ Buffer;
}
Close (Outfile);
$ Message. = $ file. "has been successfully uploaded!
/ N ";
}
Else {
$ Message. = $ file. "File suffix does not meet the requirements, upload failed!
/ N ";
}
}
$ UPFILECUNT ;
}