태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

☜[&]☞ E(い)RIS'z BLACKBASS

블로그 이미지
☜[&]☞ 誰もいなくても私はさびしくないの.。
by E(い)RIS
Candle

CALENDAR

«   2008/07   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

최근에 달린 레몬펜 쪽지

Statistics Graph
Creative Commons License

이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이선스에 따라 이용하실 수 있습니다.

최근에 달린 레몬펜 쪽지


부끄럽게도 제목의 함수를 몰라서 직접 만들었다는...

그리고 다 만들고 뿌듯해하고 있는데 내장함수를 발견했다는...

역시 배워야한다는... 흑 _ㅠ)...

출처 - 자작


// 파일의 이름을 구하는 함수
// 마지막 \의 자리를 구한 후 파일명만을 추출한다.
function getFileName(path) {
    var intIndex;
    var intIndexCount;
    var strFileName;
    for(var i=1 ; i<path.length+1 ; i++) {
        intIndex = path.substring(i-1, i);
        if(intIndex == "\\") intIndexCount = i;
    }
    strFileName = path.substring(intIndexCount, path.length);
    return strFileName;
}

// 파일의 용량을 구하는 함수
function getFileSize(path)
{
    var img = new Image();
    var strSize;
    var intSize;
    var strResult;
    img.dynsrc = path;
    intSize = img.fileSize;

    strResult = getFileSizeFormat(intSize);
    // file 태그를 지울 때 getFileSize(param1) 함수가 한번 실행되고 임의의 값인 4가 출력되는 버그가 발생
    // path == "" 조건를 주어 4 Bytes 파일을 업로드 할 때 용량이 표시가 안 되는 것을 방지.
    if ((path == "") && (strResult == 4)) strResult = "";
    return strResult;
}

// 파일 용량를 형식화 하는 함수
function getFileSizeFormat(fileSize) {
    var strFileSize
    var intFileSizeLength; //길이
    var intQuotient; //몫
    var intRest; //나머지
    var i, temp;
    var strResult;

    //파라미터 fileSize가 정수형이기 때문에 문자형으로 변환
    strFileSize = fileSize.toString();

    // 변환 된 strFileSize의 길이를 구한다.
    // intFileSizeLength는 ,(콤마)를 찍기 위한 자리 계산에 사용된다.
    intFileSizeLength = strFileSize.length;

    // 길이를 3으로 나눈 몫을 구해서 ,(콤마)의 첫번째 위치를 구한다.
    // intRest가 0이면    xxx,xxx 형식이고,
    //                1이면      x,xxx,xxx형식이고
    //                2이면 xx.xxx.xxx형식이다.
    intRest = intFileSizeLength % 3;

    // intRest를 이용하여 ,(콤마)의 갯수를 구한다.
    if (intRest == 0) {
        intQuotient = parseInt(intFileSizeLength / 3);
    } else {
        intQuotient = parseInt((intFileSizeLength / 3)+1);
    }

    for (i=0 ; i<intQuotient ; i++) {
        if (intQuotient == 1) break; // 3자리 일때는 ,(콤마) 표시를 생략한다. ex.) 123 bytes
        
        // 맨 앞의 숫자의 갯수가 3개아 아닌 경우 ex.) 12,123 bytes, 5,123,879 bytes
        if ((intRest != 0) && (i == 0))
            strFileSize = strFileSize.substring(0, intRest)+","+strFileSize.substring(intRest, strFileSize.length);

        // 맨 앞의 숫자의 갯수가 3개인 경우 ex.) 123,123 bytes, 456,789,785 bytes
        else if ((intRest == 0) && (i == 0))
            strFileSize =  strFileSize.substring(0, 3)+","+strFileSize.substring(3, strFileSize.length);

        // 맨 앞의 숫자의 갯수를 제외한 나머지 숫자의 3자리를 끊는다.
        else {
            if (i == intQuotient-1) break;

            if (intRest != 0) {
                temp = (i*3)+intRest+i;
                strFileSize =  strFileSize.substring(0, temp)+","+strFileSize.substring(temp, strFileSize.length);
            }
            else {
                temp = i*3+3+1;
                strFileSize =  strFileSize.substring(0,temp)+","+strFileSize.substring(temp, strFileSize.length);
            }
        }
    }
    strResult = strFileSize;
    document.registForm.file1.value="";
    return strResult;
}
// 표시된 숫자를 삭제
function delete_text(num) {
    if (num == 1) {
        document.registForm.filename1.value = "";
        document.registForm.sizebox1.value = "";
        // 아래 두 줄은 file 태그를 지우는 로직이다. ex.) 업로드 태그 <input type="file" name="...">
        registForm.file1.select();
        document.execCommand('Delete');
    } else if (num == 2){
        document.registForm.filename2.value = "";
        document.registForm.sizebox2.value = "";
        // 아래 두 줄은 file 태그를 지우는 로직이다. ex.) 업로드 태그 <input type="file" name="...">
        registForm.file2.select();
        document.execCommand('Delete');
    }
}
크리에이티브 커먼즈 라이선스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
TRACKBACK 0 AND COMMENT 0

ARTICLE CATEGORY

분류 전체보기 (248)
나/我/わたし/i/ (23)
SeoTajiji (3)
애드클릭스 (13)
Program(프램) (6)
블리치 (31)
Language (3)
C/C++ (5)
DB (7)
Delphi (4)
Flex (3)
JAVA (11)
XML (0)
WEB 2.0 (23)
Mac OS X (3)
ETC (112)
방통대_컴퓨터과학.. (0)

ARCHIVE