[첫화면으로]UseModWiki소스수정/화일업로드

마지막으로 [b]

12 번째 수정본
(12 번째 수정본부터 12 번째 수정본까지의 변경사항) (소소한 수정, 다른 사용자에 의한 수정)
(두 수정본의 내용이 동일하거나, 수정본을 비교할 수 없음.)

화일 업로드 기능 추가

config.pl
    ...
$MaxPost     = 1024 * 1024 * 1;  # 바이트 단위로 설정
    ...
$UploadDir   = "$DataDir/upload";   # 추가
    ...

wiki.pl
###############
### added by gypark
### 패치를 위해 추가된 환경설정 변수
use vars qw(
    $UserGotoBar $UserGotoBar2 $UserGotoBar3 $UserGotoBar4
    $ConfigFile $SOURCEHIGHLIGHT @SRCHIGHLANG $LinkFirstChar
    $EditGuideInExtern $SizeTopFrame $SizeBottomFrame
    $LogoPage $CheckTime $LinkDir $IconDir $CountDir $UploadDir  # UploadDir 추가
    );
###
###############

    my @ScriptPath = split('/', "$ENV{SCRIPT_NAME}");

    $CGI::POST_MAX = $MaxPost;
###############
### replaced by gypark
### file upload
#   $CGI::DISABLE_UPLOADS = 1;  # no uploads
    $CGI::DISABLE_UPLOADS = 0;
###
###############
    $q = new CGI;
    $q->autoEscape(undef);

###############
### added by gypark
### file upload
    if ($q->cgi_error() =~ m/^413/) {
        print $q->redirect(-url=>"http:$ENV{SCRIPT_NAME}?action=upload&error=3")
;
        exit 1;
    }
###
###############
    $Now = time;                     # Reset in case script is persistent
    $ScriptName = pop(@ScriptPath);  # Name used in links
    ...
}

sub GetSiteUrl {
    my ($site) = @_;
    my ($data, $url, $status);

    if (!$InterSiteInit) {
        $InterSiteInit = 1;
        ($status, $data) = &ReadFile($InterFile);
        return ""  if (!$status);
        %InterSite = split(/\s+/, $data);  # Later consider defensive code
###############
### added by gypark
### file upload
        $InterSite{'Upload'} = "http:$UploadDir\/";
###
###############
    }
    $url = $InterSite{$site}  if (defined($InterSite{$site}));
    return $url;
}

sub DoOtherRequest {
    ...
        } elsif ($action eq "version") {
            &DoShowVersion();
###############
### added by gypark
### 최근변경내역에 북마크 기능 도입
        } elsif ($action eq "bookmark") {
            &DoBookmark();
###
###############
###############
### added by gypark
### file upload
        } elsif ($action eq "upload") {
            &DoUpload();
###
###############
        } else {
            # Later improve error reporting
            &ReportError(Ts('Invalid action parameter %s', $action));
        }
        return;
    ...
}

sub DoEdit {
    ...
function help(s)
{
    var w = window.open(s, "Help", "width=500,height=400, resizable=1, scrollbar
s=1");
    w.focus();
}
//-->
</script>
|;

###############
### added by gypark
### file upload
    print qq|
<script language="javascript" type="text/javascript">
<!--
function upload()
{
    var w = window.open("$ScriptName?action=upload", "upload", "width=640,height=250,resizable=1,statusbar=1,scrollbars=1");
    w.focus();
}
//-->
</script>
|;
###
###############
    ...
### replaced by gypark
### 미리보기 버튼에 번역함수 적용
    # print q(<input type="button" name="prev1" value="Popup Preview" onclick="javascript:preview();">); # luke added
        print q(<input type="button" name="prev1" value=").
            T('Popup Preview') .
            q(" onclick="javascript:preview();">); # luke added
###
###############

###############
### added by gypark
### file upload
        print " ".q(<input type="button" name="prev1" value=").
            T('Upload File') .
            q(" onclick="javascript:upload();">);
###
###############
        if ($isConflict) {
            print "\n<br><hr noshade size=1><p><strong>", T('This is the text you submitted:'),
    ...
}

통채로 추가
sub DoUpload {
    my $file;
    my $upload = &GetParam('upload');
    my $prev_error = &GetParam('error', "");
    my @uploadError = (
            T('Upload completed successfully'),
            T('Invalid filename'),
            T('You can not upload html or any executable scripts'),
            T('File is too large'),
            T('File has no content'),
        );

    my $result;

    print &GetHttpHeader();
    print &GetHtmlHeader("$SiteName : ". T('Upload File'), "");
    print $q->h2(T('Upload File')) . "\n";
    if (!(&UserCanEdit("",1))) {
        print T('Uploading is not allowed');
        print $q->end_html;
        return;
    }
    if ($prev_error) {
        print "<b>$uploadError[$prev_error]</b><br><hr>\n";
    } elsif ($upload) {
        $file = &GetParam('upload_file');
        $result = &UploadFile($file);
        print "<b>$uploadError[$result]</b><br><hr>\n";
    }
    &PrintUploadFileForm();
    print $q->end_html;
}

sub PrintUploadFileForm {
    print T('Select the file you want to upload') . "\n";
    print "<br>".Ts('File must be smaller than %s MB', ($MaxPost / 1024 / 1024)) . "\n";
    print $q->start_form('post',"$ScriptName", 'multipart/form-data') . "\n";
    print "<input type='hidden' name='action' value='upload'>";
    print "<input type='hidden' name='upload' value='1'>" . "\n";
    print "<center>" . "\n";
    print $q->filefield("upload_file","",60,80) . "\n";
    print "&nbsp;&nbsp;" . "\n";
    print $q->submit(T('Upload')) . "\n";
    print "</center>" . "\n";
    print $q->endform();
}

sub UploadFile {
    my ($file) = @_;
    my ($filename);
    my ($target);

    if ($file =~ m/\//) {
        $file =~ m/(.*)\/([^\/]*)/;
        $filename = $2;
    } elsif ($file =~ m/\\/) {
        $file =~ m/(.*)\\([^\\]*)/;
        $filename = $2;
    } else {
        $filename = $file;
    }

    if (($filename eq "") || ($filename =~ /\0/)) {
        return 1;
    }

    if ($filename =~ m/(\.pyc|\.py|\.pl|\.html|\.htm|\.php|\.cgi)$/i) {
        return 2;
    }

    $filename =~ s/ /_/g;
    my ($prefix, $target, $target_full) = (1, $filename, "$UploadDir/$filename");
    while (-f "$target_full") {
        $prefix++;
        $target = "$prefix"."_$filename";
        $target_full = "$UploadDir/$target";
    }

    &CreateDir($UploadDir);

    open (FILE, ">$target_full") || die Ts('cant opening %s', $target_full) . ": $!";
    binmode FILE;
    while (<$file>) {
        print FILE $_;
    }
    close(FILE);
    chmod(0644, "$target_full");

    if ((-s "$target_full") > $MaxPost) {
        unlink "$target_full";
        return 3;
    }

    if ((-s "$target_full") == 0) {
        unlink "$target_full";
        return 4;
    }

    print T('Following is the Interlink of your file') . "<br>\n";
    print "<div style='text-align:center; font-size:larger; font-weight:bold;'>\n";
    print "Upload:$target\n";
    print "</div>\n";
    return 0;
}

translations/korean.pl
Upload File
화일 업로드
Upload completed successfully
업로드가 성공적으로 끝났습니다
Invalid filename
화일 이름이 올바르지 않습니다
You can not upload html or any executable scripts
html 또는 실행 스크립트는 올릴 수 없습니다
File is too large
화일이 너무 큽니다
File has no content
화일의 내용이 없습니다
Following is the Interlink of your file
다음 주소를 복사해서 사용하세요
Uploading is not allowed
업로드가 허용되지 않습니다
Select the file you want to upload
업로드할 화일을 선택하세요
File must be smaller than %s MB
화일 크기는 %s MB 이하여야 합니다.
Upload
업로드
cant opening %s
%s 를 열 수 없습니다

Notes

도대체 왜 리눅스에서는 안 되는 걸까요? 화일명의 전체 경로가 제대로 넘어가지 않는 듯 합니다.
-- Raymundo 2003-3-16 7:22 am

리눅스 뿐만이 아니라 윈도 피닉스, 그러니깐 모질라, 넷스까지 포함하게 되겠네요.. 저것들이 전부 제대로 업이 안되었습니다. 모질라는 주소전송시 UTF-8로 변환을 무조건 수행하는 거 같은데, 이것을 어떻게 해줘야 좋을지 몰라서 저는 그냥 이대로 쓰고 있습니다만.. IE에서도 저 옵션을 끄지않고 한글화일을 올리려하니 제대로 안되더군요. ㅜㅡ
-- Bab2 2003-3-16 4:03 pm

유닉스 쪽에서는, 화일명을 전달할 때 전체 경로가 전달되는 게 아닌가 보더라고요. 그래서 기존의 if 문 (전체 경로에서 화일명만 추출해 내는) 에서 제대로 걸리지 않아서 문제가 되었던 듯 합니다. 저 부분을 수정했더니, 모질라에서는 제대로 동작하는 것을 확인했습니다. konqueror 는 당장 자바스크립트 쪽에서 말썽이었는데 그건 일단 넘어가고, 업로드의 경우 화일명에 한글이 있으니 안 되더군요. 디렉토리에 한글이 있는 것은 상관없었습니다.
-- Raymundo 2003-3-17 12:20 am

혹시 MS윈도에서 IE 외에 다른 브라우저를 사용하시는 분들 계시면 연습장에서 업로드 테스트 좀 해봐주세요~
-- Raymundo 2003-3-17 12:28 am


위키위키분류

이 수정본 편집일: 2003-3-21 9:46 pm (변경사항 [d])
2369 hits | Permalink | 변경내역 보기 [h] | 현재 수정본 보기 | 12 번째 수정본 소스 보기