[그누보드][ajax][첨부파일 올리기][비동기][wr_id값 ?어떻게??]

[그누보드][ajax][첨부파일 올리기][비동기][wr_id값 ?어떻게??]

QA

[그누보드][ajax][첨부파일 올리기][비동기][wr_id값 ?어떻게??]

본문

안녕하세요~!!! 

그누보드 ajax로 첨부파일을 비동기 방식으로 업로드하는 기능을 구현중인데요..

http://www.plupload.com/examples/  

위 링크의 플러그인을 적용하였습니다.

 

현재, ftp로 이미지가 정상적으로 업로드되는것까지 구현이 됫는데요..

 

문제는................

 

이 파일을, db로 해당 테이블에 해당 wr_id 값에 맞춰 올려주어야하는데...

이게 문제네요...

 

어떻게 wr_id 값을 가져와서 보내줘야하나요 ?... 주소값에 wr_id 값도 없을뿐더러....

 

파일을 전송하는 스크립트 안에서 

ajax  ( data :wr_id 하자니 ...

플러그인 자체가.....너무 ..고난도 소스라...

 

이건 또 아닌것같고...

 

아래 파일이 실제 ftp로 이미지를 업로드 하는 파일인데..

 

이안에서 모두 해결을 해야될것같다는 생각이 최선이라 생각되는데요...

 

어떻게..wr_id 값을 가져오지라는.... 무서운 ....보이지않는 벽에 막혀버렷습니다...

 

bo_table 값도 가져와지지않더라구요...그래서 "/order/" 이렇게 직접...폴더명을 입력해주엇는데..

 

common.php 파일은 정상적으로 불러와지고있습니다...

 

어떤 방법이 잇나요 ?

 

wr_id 값을 가져오는?

 

그리고.... 다수의 파일을 동시에 업로드할수 잇는 플러그인인데..

 

어떻게 개별 값을 가져올수잇나요 ?

 

$file[i][file] ? 이런식으로...

무턱대고 인터넷을 뒤져보니..

// Check if file has been uploaded

if (!$chunks || $chunk == $chunks - 1) {

// Strip the temp .part suffix off 

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

 

이 사이에 넣어야 한다는..것같은데...

}

맞을까요 ?/

while 또는. for 문없이 그냥 돌리나요 ?.....

 

대책없는 두서없는....벽에 가로막힌....나약한 미생을 구제해주세요...

 

 

 


<?php
include_once('./_common.php');
$wr_id= $_GET["wr_id"]//??
 
/**bant/skin/board/order
 * upload.php
 *
 * Copyright 2013, Moxiecode Systems AB
 * Released under GPL License.
 *
 * License: http://www.plupload.com/license
 * Contributing: http://www.plupload.com/contributing
 */
 
#!! IMPORTANT: 
#!! this file is just an example, it doesn't incorporate any security checks and 
#!! is not recommended to be used in production environment as it is. Be sure to 
#!! revise it and customize to your needs.
 
 
// Make sure file is not cached (as it happens for example on iOS devices)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
 
/* 
// Support CORS
header("Access-Control-Allow-Origin: *");
// other CORS headers if any...
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
	exit; // finish preflight CORS requests here
}
*/
 
// 5 minutes execution time
@set_time_limit(5 * 60);
 
// Uncomment this one to fake upload time
// usleep(5000);
 
// Settings
$targetDir = G5_DATA_PATH."/file/order";
//$targetDir = 'uploads';
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds
 
 
// Create target dir
if (!file_exists($targetDir)) {
	@mkdir($targetDir);
}
 
// Get a file name
if (isset($_REQUEST["name"])) {
	$fileName = $_REQUEST["name"];
} elseif (!empty($_FILES)) {
	$fileName = $_FILES["file"]["name"];
} else {
	$fileName = uniqid("file_");
}
 
$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
 
// Chunking might be enabled
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
 
 
// 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);
 
// Check if file has been uploaded
if (!$chunks || $chunk == $chunks - 1) {
	// Strip the temp .part suffix off 
	rename("{$filePath}.part", $filePath);
	
	 $sql = " insert into $g5[board_file_table]
                    set bo_table = '$bo_table',
                        wr_id = '$wr_id',
                        bf_no = '$i',
                        bf_source = '',
                        bf_file = '',
                        bf_content = '',
                        bf_download = 0,
                        bf_filesize = '',
                        bf_width = '',
                        bf_height = '',
                        bf_type = '',
                        bf_datetime = '$g5[time_ymdhis]' ";
        sql_query($sql);
		
}
 
// Return Success JSON-RPC response
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
 

이 질문에 댓글 쓰기 :

답변 1

도큐먼트 보시면 ​multipart_params이라고 있네요.

 

이걸로 값 보내시면 되요.

 

e95f32c6906a59aa0f2d3378e2721281_1422941274_8436.PNG
 

멀티파트파람으로 값넘겨서 리퀘스트 프린트알로 뽑아본거에요

오....................................드래곤님!! 답변감사합니다...

오...... 신기하네요...

그런데...제가궁금한것은...

새글일경우에!
wr_id값은 존재하지않는거아니예요 ??
data = "<?php echo $wr_id;?>" 하고 이값을 멀티파트파람으로 보내봣는데...
값은 계속 0 으로 뜨네요...ㅠㅠ

흠....

어떻게...해당 작성하는글의 번호를...가져올까요...

아................................................................ㅎㅎ

wr_id값이 안나온다고하셔서 그생각은 못했네요. ㅎㅎㅎㅎ

다중업로드할때 사용하던방법인데요 임시저장할 테이블을 하나 작성하고 첨부파일을 올리면 임시저장할 테이블에 파일정보와 세션값이나 아이디값같은 누가 올렸는지 구분할수 있는 유일한 값을 넣어서 저장해두셨다가 나중에 글작성 완료하고 인서트문 때릴때 임시저장한 테이블에서 값을 가져와서 같이 인서트문에 포함하고 그 테이블에 저장된 값은 지우시면되요.

그리고 글작성 페이지에 들어올때마다 유일값으로 검색해서 임시저장하는 테이블에 값이 있다면 지워주시구요. 그러면 이전에 남긴 첨부파일들이 같이 남아서 올라가는 일은 없으실꺼에요~

헐............................................................죄송합니다....................어렵네요...ㅠㅠ...무슨 말씀인가요 ?........................

죄송합니다 .....ㅠㅠ

...........

음...

-게시판테이블
-file 테이블
일때
-임시테이블을 하나 더 만들어

처음 파일을 업로드할떄는
임시테이블로 얹고,

게시판 글작성할때 위 임시테이블을

file 테이블로 옮기시라는 말씀인가요!?!??

........................10번 글을 읽어보니...이런것같은데...

그리고,, 저 혹시 file 테이블에 해당 파일 내용 insert 할떄
type, size ,content를 모두 입력해야 하나요 ??

꼭?  type,size는...갖고올방법이 없는것같아서요..

제가 그누보드를 안써봐서 파일테이블이 따로 있는지 몰랐네요;;;

g5_board_file 이거 맞죠?

여분컬럼이 없는거 같으니깐 여분컬럼 하나 추가해주시구요

plupload에서 업로드할때 wr_id값은 임시로 아무거나 겹치지 않게 넣어주시고 새로만든 여분컬럼에 구분값 넣어주셨다가

게시글 작성완료에서 db에 insert 때릴때 board_file에 업데이트문으로 구분값을 찾아서 wr_id값을 업데이트 해주시면 될것같아요~

호......................어렵네요............................................................
업데이트문에서 찾는게..조금 어려울것같지만..한번 해봐야겟어요
해당 값은..........
음..........날짜 같은걸.....넣어주면될까요 ??????...

그런데...그누보드를...안써보셧군요...

답변을 작성하시기 전에 로그인 해주세요.
전체 15
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT