멀티 파일 업로드 스킨 소스 분석 부탁드립니다.

멀티 파일 업로드 스킨 소스 분석 부탁드립니다.

QA

멀티 파일 업로드 스킨 소스 분석 부탁드립니다.

답변 1

본문

루미집사 님의 Plupload 적용한 멀티 업로드 스킨의 소스를 뜯어 보고 있습니다.

 

스킨 URL : https://sir.kr/g5_skin/38514

 

 

위스킨중 실제 파일이 업로드 되는 부분이 어딘지 모르겠네요...

 

file_upload.php 소스 부분에서 db를 등록하는 부분이 있는데..

 

이곳에서 파일을 업로드를 하나요? 그렇다면 어느부분에서 템프파일이 실제 서버로 이동이 되나요?

 



// Remove old temp files    
if ($cleanupTargetDir) {
    if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
    }
    while (($file = readdir($dir)) !== false) {
        $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
        // If temp file is current file proceed to the next
        if ($tmpfilePath == "{$filePath}.part") {
            continue;
        }
        // Remove temp file if it is older than the max age and is not the current file
        if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
            @unlink($tmpfilePath);
        }
    }
    closedir($dir);
}
// Open temp file
if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
    die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
if (!empty($_FILES)) {
    if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
    }
    // Read binary input stream and append it to temp file    
    if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
    }
}
else {    
    if (!$in = @fopen("php://input", "rb")) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
    }
}
while ($buff = fread($in, 4096)) {
    fwrite($out, $buff);
}
@fclose($out);
@fclose($in);
$fileNameSub  = uploadfilenamechange($fileName); // 원본파일명을 변경한다.
$fileNameSubPath = $targetDir . DIRECTORY_SEPARATOR . $fileNameSub; // 파일저장위치
// Check if file has been uploaded
if (!$chunks || $chunk == $chunks - 1) {
    // Strip the temp .part suffix off 
    rename("{$filePath}.part", $fileNameSubPath);
    $img = @getimagesize($fileNameSubPath); // 파일정보
    // 이미지 파일인데 이미지파일타입이 아니면 파일을 삭제하고 등록하지 않는다.
    if ( preg_match("/\.({$config['cf_image_extension']})$/i", $ori_fileName) || preg_match("/\.({$config['cf_flash_extension']})$/i", $ori_fileName) ) {
            if ($img['2'] < 1 || $img['2'] > 16) {
                @unlink($fileNameSubPath);
                die('{"jsonrpc" : "2.0", "result" : null, "id" : "id2"}');
            }
    }
    $fileSize = filesize($fileNameSubPath); // 파일 size
    
    // "bf_no" 값 구하기
    $row = sql_fetch(" SELECT max(bf_no) AS bf_no FROM {$g5['board_file_table']} WHERE bo_table = '{$bo_table}' AND wr_id = '{$wr_id}' ", TRUE);
    $bf_no =  (isset($row['bf_no']))? ($row['bf_no'] + 1):'0';
    // 파일정보를 DB에 저장한다
    $sql = "INSERT INTO
                {$g5['board_file_table']}
            SET
                bo_table    = '{$bo_table}',
                wr_id       = '{$wr_id}',
                bf_no       = '{$bf_no}',
                bf_source   = '{$ori_fileName}',
                bf_file     = '{$fileNameSub}',
                bf_content  = '',
                bf_download = 0,
                bf_filesize = '{$fileSize}',
                bf_width    = '{$img[0]}',
                bf_height   = '{$img[1]}',
                bf_type     = '{$img[2]}',
                bf_datetime = '".G5_TIME_YMDHIS."' ";
    sql_query($sql, true);
    
    unset($img);
    unset($fileSize);
}

이 질문에 댓글 쓰기 :

답변 1

Plupload 는 https://www.plupload.com/

 

처음 보는 것이라.. 맞을지 모르겠습니다만, 추측으로는..

 

rename("{$filePath}.part", $fileNameSubPath);

 

부분이 'tmp 파일이 실제 저장위치 이동' 코드 인 것 같습니다.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 30
© SIRSOFT
현재 페이지 제일 처음으로