#!/usr/bin/perl
$basedir = "파일저장 절대경로를 지정"; #예를 들면 $basedir = "/home/happycgi/public_html/file"; 이런식으로..
my $buffer; $time = time; $work = $ENV{"QUERY_STRING"}; @pairs_end = split(/&/, $work); foreach $pair (@pairs_end) { ($kname, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $END{$kname} = $value; }
if ($ENV{'REQUEST_METHOD'} eq "POST") { binmode STDIN; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } my ($qx_name, $value); if ($buffer !~ /\n/) { for (split /&/, $buffer) { ($qx_name, $value) = split /=/; $qx_name =~ y/+/ /; $qx_name =~ s/%(..)/chr hex $1/ge; $value =~ y/+/ /; $value =~ s/%(..)/chr hex $1/ge; $$qx_name = $value; } } else { # 파일 업로드 my ($qx_name, $value); my ($border) = ($buffer =~ /^(.+?)\r?\n/); $buffer =~ s/${border}--$//; my $bad_char = '`~!@#%^&*()|,<>?;:\'"[]{}';
for (split /$border/, $buffer) {
next if $_ eq ''; s/^\r?\n//;
if (/name="FILE(\d+)"; filename="(.+?)"/i) { my ($FILE_VAR) = $1; next if $2 eq ''; my ($FILE_NAME) = $2 =~ m{([^\\^/]+)$}; $FILE_NAME =~ s/[$bad_char]//g; #파일이름 배열저장 $FILES{'file'}->{name} = $FILE_NAME; s/^.+?\r?\n\r?\n//s; s/\r?\n$//s; if($_ eq '') { $FILES{'file'}->{name} = ''; next; } else { open (A,">$basedir/$time-$FILE_NAME"); binmode(A); print A $_; close (A); } #파일내용 배열저장 #$FILES{'file'}->{data} = $_; my ($File_Name_In) = "FILE" . "$FILE_VAR"; $Field{$File_Name_In} = $FILE_NAME;
} else { s/^.+?name\=\"(\S+?)\"\r?\n\r?\n(.+?)\r?\n$//s; ($qx_name = $1) =~ tr/\r//d; ($value = $2) =~ tr/\r//d; $$qx_name = $value; } } #for }#else
|