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

마지막으로 [b]

1. 화일 업로드 기능 추가
1.1. 사용법
1.2. 부작용 : 모름
1.3. config.pl 수정
1.4. wiki.pl 수정
1.5. translation/ko_KR.*.pl 수정
1.6. 추가 업데이트 내역
1.7. Notes

1. 화일 업로드 기능 추가

1.1. 사용법

### 화일 업로드와 오에카키 저장을 위한 디렉토리 (내부 경로를 사용)
$UploadDir   = "./upload";  # by gypark. file upload
### 화일 업로드와 오에카키 저장을 위한 URL (http:// 시작하는 절대경로 사용)
$UploadUrl   = ""; # by gypark, URL for the directory containing uploaded file
                   # if undefined, it has the same value as $UploadDir

1.2. 부작용 : 모름

1.3. config.pl 수정

config.pl
    ...
$MaxPost     = 1024 * 1024 * 1;  # 바이트 단위로 설정, 이 경우 1MB 가 된다.
    ...
$UploadDir   = "$DataDir/upload";   # 추가
$UploadUrl   = "";                  # 추가
    ...

1.4. 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  $UploadUrl   # UploadDir, UploadUrl 추가
    );
###
###############

    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;
    }
    $UploadUrl = "http:$UploadDir" if ($UploadUrl eq "");
###
###############
    $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;
###############
### replaced by gypark
### file upload
#       ($status, $data) = &ReadFile($InterFile);
#       return ""  if (!$status);
#       %InterSite = split(/\s+/, $data);  # Later consider defensive code
        ($status, $data) = &ReadFile($InterFile);
        if ($status) {
            %InterSite = split(/\s+/, $data);
        }
        $InterSite{'Upload'} = "$UploadUrl\/";
###
###############
    }
    $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'),
            T('Failed to get lock'),
        );

    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;
    &RequestLockDir('upload', 5, 2, 0) || return 5;
    my $target      = GetUniqueUploadFilename( $UploadDir, $filename );
    my $target_full = "$UploadDir/$target";

    &CreateDir($UploadDir);

    if (!open (FILE, ">$target_full")) {
        &ReleaseLockDir('upload');
        die Ts('cant opening %s', $target_full) . ": $!";
    }
    &ReleaseLockDir('upload');
    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 ";
    print $q->button(
                -name=>T("Copy"),
                -onClick=>"copy_clip('','Upload:$target')"
                );
    print "</div>\n";
    return 0;
}

1.5. translation/ko_KR.*.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
화일의 내용이 없습니다
Failed to get lock
업로드를 위한 lock 을 얻지 못했습니다
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 를 열 수 없습니다

1.6. 추가 업데이트 내역

ext1.42a 에서 UploadFile 함수에서 한 단락이 제거되었습니다. ( if ($prefix == 0) { } else { } 구문 )
-- Raymundo 2003-3-25 5:45 pm

ext1.42b - 소스들이 재수정 되었습니다. 꼭 확인하세요 /UploadedFiles매크로/오에카키도 같이 수정됩니다.

-- Raymundo 2003-3-26 12:06 am

ext2.4 - 업로드된 파일의 인터링크 주소를 클립보드에 복사할 수 있는 버튼 추가.

ext2.17a - 파일 이름이 중복될 때 확장자 직전에 숫자를 붙이도록 변경. UseModWiki소스수정/GetUniqueUploadFilename함수를 사용

-- Raymundo 2012-1-29 11:25 pm

1.7. 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


여러 사람이 동시에 같은 이름의 화일을 업로드하는 경우를 고려하여 저장되는 이름을 결정하는 부분에 lock 을 걸도록 수정했습니다. 그리고 같은 이름의 화일이 존재할 경우 앞에 붙일 숫자를 결정하는 부분을 별도의 함수 (/GetLastPrefix함수)로 분리해서 재사용할 수 있도록 했습니다.
-- Raymundo 2003-3-23 4:01 am

이름:  
Homepage:
내용:
 

위키위키분류

마지막 편집일: 2012-1-29 11:25 pm (변경사항 [d])
2115 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기