안녕하세요 오랜만에 질문을 남기게 되었습니다
현재 만드는 모듈에 게시글 작성시 섬네일로 쓸 이미지파일을 첨부받은 뒤에 list.html 쪽에 [이미지] [제목] 이런식으로 게시판처럼 만드려고하는데요
write.html 에서 파일첨부를
<tr>
<th>{$lang->file}</th>
<td class="left"><input type="file" name="upfile"></td>
</tr>
이렇게 해서 파일 첨부를 받습니다
그리고 프론트 컨트롤러에서
function procShopContentWrite() {
// request 값을 모두 받음
$obj = Context::getRequestVars();
// 현재 모듈번호 확인
$obj->module_srl = Context::get('module_srl');
//shop_srl 확인
$shop_srl = Context::get('shop_srl');
// shop_srl에 따라 새로 입력하거나 수정하기 위해
if($shop_srl)
{
// module_srl이 있으면 update
$output = executeQuery("shop.updateShop", $obj);
$this->setMessage('success_updated');
}
else
{
//module_srl번호를 넘겨주어야 하므로
$module_info = Context::get("module_info");
$module_srl = $module_info->module_srl;
//첨부파일에 대한 정보는 Context::get으로 name을 입력만 해주면 됩니다.
$upfile= Context::get("upfile");
//upload_target_srl을 입력해줍니다. 여기서는 테스트를 위해 고정값을 입력했습니다. 필요한 숫자를 구하시면 되겠죠.
$upload_target_srl = $shop_srl;
//XE에서는 file이란 module을 제공하고 있습니다.
$oFileController = getController('file');
$output = $oFileController->insertFile($upfile, $module_srl, $upload_target_srl);
// module_srl이 없으면 insert
$output = executeQuery("shop.insertShop", $obj);
$this->setMessage('success_registed');
var_dump($upfile);
}
}
// request 값을 모두 받음
$obj = Context::getRequestVars();
// 현재 모듈번호 확인
$obj->module_srl = Context::get('module_srl');
//shop_srl 확인
$shop_srl = Context::get('shop_srl');
// shop_srl에 따라 새로 입력하거나 수정하기 위해
if($shop_srl)
{
// module_srl이 있으면 update
$output = executeQuery("shop.updateShop", $obj);
$this->setMessage('success_updated');
}
else
{
//module_srl번호를 넘겨주어야 하므로
$module_info = Context::get("module_info");
$module_srl = $module_info->module_srl;
//첨부파일에 대한 정보는 Context::get으로 name을 입력만 해주면 됩니다.
$upfile= Context::get("upfile");
//upload_target_srl을 입력해줍니다. 여기서는 테스트를 위해 고정값을 입력했습니다. 필요한 숫자를 구하시면 되겠죠.
$upload_target_srl = $shop_srl;
//XE에서는 file이란 module을 제공하고 있습니다.
$oFileController = getController('file');
$output = $oFileController->insertFile($upfile, $module_srl, $upload_target_srl);
// module_srl이 없으면 insert
$output = executeQuery("shop.insertShop", $obj);
$this->setMessage('success_registed');
var_dump($upfile);
}
}
이렇게 했는데 왜..
var_dump 로 보면 null 값이 들어갈까요?ㅜㅜ
http://dingadinga.tistory.com/183 이쪽에서 XE File Upload 부분을 봐서 해본건데 제가 잘못넣은건지...ㅎ
테스트로 <input type="hidden" name="tests" value="6" /> 해서 컨트롤러에서 찍어보면 6이 제대로나오는데.. file 같은경우는 null값이 떠버리네요...
네비
Lv. 3
댓글 14
null이 날라왔다면, 폼 전송 단계에서 파일이 아예 넘어오지 않았다는 거에요.
enctype="multipart/form-data"가 추가가 안되있어서 추가하고 썼는데.. 그래도 안되네요ㅎ.. 도대체 뭐가 잘못된건지...ㅜㅜ
아니면 혹시 이와 같은 첨부파일기능이 달린 참고할만한 모듈이있을까요...
Resource 모듈을 참고하시면 XML JS Filter를 이용하면서도 파일 첨부를 할 수 있으니, 한 번 훑어보세요.
워낙 방대한 내용이라 일일이 설명해드리기가 어렵네요.
https://xe1.xpressengine.com/index.php?mid=download&package_id=18324191
object(stdClass)#117 (12) {
["_filter"]=>
string(14) "content_insert"
["error_return_url"]=>
string(45) "/index.php?mid=tests&act=dispShopContentWrite"
["act"]=>
string(20) "procShopContentWrite"
["mid"]=>
string(5) "tests"
["module_srl"]=>
string(3) "136"
["regdate"]=>
string(8) "20161122"
["shop_infomation"]=>
string(13) "내용"
["member_srl"]=>
string(1) "0"
["shop_title"]=>
string(6) "제목"
["shop_category"]=>
string(6) "없음"
["shop_price"]=>
string(3) "222"
["module"]=>
string(4) "shop"
}
보면... 프론트쪽에서 file input name가 upfile 로되어있는데 upfile라는게 없는걸보면 못넘어온것같습니다..
필터에서 file 업로드체크에관한 노드는 적지않았습니다 모듈첨부해두겠습니다 ㅜㅜ
shop.zip
write.html
4번 라인 <form action="/" method="get" enctype="multipart/form-data" onsubmit="return procFilter(this, content_insert);" >
method="get" 를 post 로 해보세요.
그리고 4 랑 52 라인 onsubmit="return procFilter(this, content_insert);" <- 이거 빼보시구요..
act 가 빠진거 같아요
onsubmit 은 빼시고..
<input type="hidden" name="act" value="proc이름" /> 을 form 에 추가해보세요.