[그누보드][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"}');