| 제목 | 파일 업로드 질문드립니다. | ||
|---|---|---|---|
| 글쓴이 | 책상다리 | 작성시각 | 2014/02/21 17:40:28 |
|
|
|||
|
이미지 업로드 게시판을 하나 만들어야 해서, 책을 참고로 해서...뭐 책과 똑같습니다;;; 여튼 그렇게 만들었는데, 글쓰기 누르면 애러도 없고 그냥 리스트 페이지로 돌아옵니다;;; 프로파일링 해봐도 특별한건 안보이고..답답하네요 ㅠ echo로 이것저것 찍어봐도 나오는게 없고...화면에 에러라도 발생하면 그부분이라도 고쳐보겠는데..;;
컨트롤러
public function write()
{
$this->output->enable_profiler(TRUE);
$this->load->library('form_validation');
//폼 검증할 필드와 규칙 사전 정의
$this->form_validation->set_rules('subject','제목','required');
$this->form_validation->set_rules('contents','내용','required');
if( $this->form_validation->run() == FALSE )
{
$this->load->view('image/image_write_v');
}
else
{
$config = array(
'upload_path' => 'uploads/',
'allowed_types' => 'gif|jpg|png',
'encrypt_name' => TRUE,
'max_size' => '1000'
);
$this->load->library('upload',$config);
if(!$this->upload->do_upload())
{
$data['error'] = $this->upload->display_errors();
$this->load->view('image/image_write_v',$data);
}
else
{
$upload_data = $this->upload->data();
$upload_data['subject'] = $this->input->post('subject',TRUE);
$upload_data['contents'] = $this->input->post('contents',TRUE);
$upload_data['user_name'] = $this->input->post('name');
$upload_data['user_id'] = $this->input->post('username');
$result = $this->image_m->insert_image($upload_data);
redirect('/image'); exit;
}
}
}
모델
function insert_image($arrays)
{
$detail = array(
'file_size'=>(int)$arrays['file_size'],
'image_width'=>$arrays['image_width'],
'image_height'=>$arrays['image_height'],
'file_ext'=>$arrays['file_ext']
);
$insert_array = array(
'user_id' => $arrays['user_id'],
'user_name' => $arrays['user_name'],
'subject' => $arrays['subject'],
'contents' => $arrays['contents'],
'file_path' => $arrays['file_path'],
'file_name' => $arrays['file_name'],
'original_name' => $arrays['original_name'],
'detail_info' => serialize($detail),
'reg_date' => date("Y-m-d H:i:s")
);
$this->db->insert('image',$insert_array);
$result = $this->db->insert_id();
return $result;
}
뷰
<article id="board_area">
<header>
<h1></h1>
</header>
<?php
$attributes = array('class' => 'form-horizontal','id'=>'upload_action');
echo form_open_multipart('/image',$attributes);
?>
<fieldset>
<legend>이미지 게시판 글쓰기</legend>
<div class="control-group">
<label class="control-label" for="input01">제목</label>
<div class="controls">
<input type="text" class="text" id="input01" name="subject">
<p class="help-block">게시물의 제목을 써주세요</p>
</div>
<label class="control-label" for="input02">내용</label>
<div class="controls">
<textarea id="input02" cols='100' rows="25" name="contents"></textarea>
<p class="help-block">게시물의 내용을 써주세요.</p>
</div>
<label class="control-label" for="input03">사진 업로드</label>
<div class="controls">
<input type="file" class="input-xlarge" id="input03" name="userfile" value="<?php echo set_value('userfile');?>">
<p class="help-block">파일을 선택해주세요</p>
</div>
<div class="form-actions">
<button type="button" class="btn btn-primary" id="write_btn">작성</button>
<input type="button" class="btn" value="취소" onclick="history.back()">
</div>
</div>
</fieldset>
</form>
</article>
입니다. CI 접한지 이제 6개월정도 된거 같은데... 아직도 이런데서 해매고 있으니..착찹합니다 ㅠ |
|||
| 다음글 | controller, model, view 한곳으로 묶... (2) | ||
| 이전글 | nginx 설정관련 질문입니다. (2) | ||
|
한대승(불의회상)
/
2014/02/21 17:48:09 /
추천
0
|
|
책상다리
/
2014/02/21 18:01:32 /
추천
0
아아아아아아 ㅠㅠ
감사합니다......제가 구조파악을 잘못하고 있었네요..저걸 리스트 부분으로 넘겨주면 안되는건데..아.... |
위 소스는 아래 부분에 문제가 있군요.
echo form_open_multipart('/image',$attributes);무엇이 문제인지 잘 생각해 보세요. ^^