CI 묻고 답하기

제목 파일업로드폼은 따로 만들어야하나염?
글쓴이 승버미 작성시각 2011/11/08 22:08:13
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 16386   RSS
 contoller

<?php
class User_ci extends CI_Controller {
 
 function User_ci() {
  parent::__construct();
 }
 
 
 function index() {
  
  
  $this->load->view('user_add_view');
  
 }
 
 function user_add() {
  //포스트타입으로데이터받기
  $data_p = $this->input->post();
  //파일 업로드 세팅
  $config['upload_path']='./img/';
  $config['allowed_types']='gif|jpg|png';
  
  $this->load->library('upload',$config);
  $field_name = "user_img";
  
  if(! $this->upload->do_upload($field_name)) {
   
   $error = array('error' => $this->upload->display_errors());
   
  }else {
   $data = array('upload_data' => $this->upload->data());
   
   $file_path = $data['upload_data']['file_name'];
   
  }
  //모델로드
  $this->load->model('user_model');
 //값이들어갔는지 테스트 
 echo '<pre>';
  print_r($data_p) ;
  print_r($file_path) ;
  
  echo '</pre>';
  //  $user_data = $this->user_model->user_model_add($data,$file_path);
  
 }
 
 
}



model

<?php
class User_model extends CI_Model {
 
 function User_model() {
  
  parent::__construct();
 }
 
 function user_model_add($data,$file_path) {
  
  $result = $this->db->insert('user',$data,array('user_img' => $file_path));
  
 }
 
 
}


view

<html>
<head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
 <meta name="author" content="">
 <title>user_add_view</title>
</head>
<body>
 <form action="index.php/user_ci/user_add" method="post" enctype="multipat/form-data">
  <table>
   <tr>
    <td>I D : </td>
    <td><input type="text" name="user_id"></td>
   </tr>
   <tr>
    <td>PWD : </td>
    <td><input type="password" name="user_pwd"></td>
   </tr>
   <tr>
    <td>email:</td>
    <td><input type="text" name="user_eamil"></td>
   </tr>
   <tr>
    <td>tel :</td>
    <td><input type="number" name="user_tel"></td>
   </tr>
   <tr>
    <td>img : </td>
    <td><input type="file" name="user_img"></td>
   </tr>
   <tr>
    <td><input type="submit" value="입력"></td>
   </tr>     
  </table>
 </form>
</body>
</html>

DB에 저장하려고 하는거고염 upload파일은 경로만 db에 저장하려하는데 upload파일 폼을따로 만들면 값이 들어가는데
폼을 하나루 만드려니 오류가나네염 ...
data_p는 값이 들어오는데 upload할 경로값이 file_path에서 오류나네염 ㅜㅜ
뭐가 틀렸는지좀 알려주세염

오류 내용
Array
(
    [user_id] => ysb
    [user_pwd] => ysb334
    [user_eamil] => ysb@nate.com
    [user_tel] => 1312312312
)

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: file_path

Filename: controllers/user_ci.php

Line Number: 40



 다음글 CI 를 다운받아서 첨 사용해 보는데요. (11)
 이전글 jquery 유효성검사 문의좀드립니다. (3)

댓글

변종원(웅파) / 2011/11/08 22:19:32 / 추천 0
제대로 작동을 하는지 확인하시려면 각 if문 안에서 내용들을 출력해봐야 합니다.
위 구문은 if문이 작동하는지 안하는지 모르고  외부에서 결과값만 찍어보니 그런 겁니다.
if문 내부에 있는 $error변수를 화면에 출력해보세요. 답이 있습니다.
어떤 이유(확장자가 틀리거나 파일이 크거나 디렉토리 퍼미션이 없거나)로 업로드 실패한겁니다.

질문하시기 전에 해당 에러내용 출력해보시고 application/logs 디렉토리의 로그도 보시구요.
아파치 에러로그까지 확인하는 습관을 들이시면 개발하시는데 도움이 됩니다.
한대승(불의회상) / 2011/11/08 22:34:05 / 추천 0
$file_path 변수가 선언되어 있지 않군요 ^^
파일 저장 할 경로를 file_path로 설정 하신거 같은데 그 값이 없어서 에러가 났나 봅니다.

업로드가 안되면 업로드 폴더의 퍼미션(권한)도 확인 하세요