CI 묻고 답하기

제목 upload 라이브러리가 정상적으로 작동하지 않습니다
글쓴이 에카 작성시각 2013/11/19 22:15:30
댓글 : 6 추천 : 0 스크랩 : 0 조회수 : 17006   RSS
 남들은 되는게 왜 전 하나씩 안될까요 ㅡㅡ;;; 짜증이 밀려오기 시작합니다..
    $upload_config = Array(
     'upload_path' => './attachment/temporary/',
     'allowed_types' => 'gif|jpg|jpeg|png',
     'max_size' => '10240'
    );
    $this->load->library('upload', $upload_config);

    if( ! $this->upload->do_upload()) {
     echo $this->upload->display_errors();
     print_r($_FILES);
    } else {
    }
PHP 소스입니다.

<div id="document-write">
 <form method="POST" action="/submit/article/<?php echo $CurrentBoardID; ?>" enctype="multipart/form-data">
    <input type="text" id="inputDocumentTitle" name="document-title" />
    <textarea id="documentContent" name="document-content" rows="12"></textarea>
    <input type="file" name="file_attachment" />
  <input type="submit" value="작성" />
 </form>
</div>
HTML 소스입니다.


이 상태로 진행하면 다음과 같은 내용이 출력됩니다.

You did not select a file to upload.
 
Array ( [file_attachment] => Array ( [name] => WD MybookLive.PNG [type] => image/png [tmp_name] => /tmp/phpLgz5Sn [error] => 0 [size] => 5898 ) )

즉, $_FILES 로 파일은 읽어왔지만, upload 라이브러리($this->upload->do_upload)는 전혀 못읽어온다는 것입니다.
뭐가 문제일까요. 뭘 고쳐야될까요. 막막합니다. 살려주세요.
 다음글 $_POST값을 이용하는 메써드를 호출할려고 합니다. (1)
 이전글 죄송 하지만 이 소스 한줄씩 설명 해주실분 없나요? (6)

댓글

criuce / 2013/11/19 23:13:04 / 추천 0
do_upload('file_attachment')

이렇게 하셔야 해요.
에카 / 2013/11/20 00:31:59 / 추천 0
 criuce님 // 여전히 작동을 안하네요 ㅠㅠㅠ하...
에카 / 2013/11/20 00:35:15 / 추천 0
문제 해결봤습니다.. 소스에 있는건 아니고 엉뚱한곳에 있었네요.
HTML에서 다중업로드를 위해서 name부분에 []를 붙여둔게 화근이였습니다.
업로드 라이브러리로는 지원이 안되었던게 문제였네요. 이걸 어떻게 해야될지 고민입니다.
criuce / 2013/11/20 00:46:57 / 추천 0
다중업로드는 팁게시판에 맨 위에 참고할만한 게시물이 있네요.
에카 / 2013/11/20 01:10:03 / 추천 0
TIP게시판은 볼생각도 못했네요 ㅠㅠ stackoverflow에서 찾고있었습니다..
정말 감사합니다!
에카 / 2013/11/20 01:26:25 / 추천 0
전 이런식으로 해결했습니다. 혹시나 해서 적어둡니다. 'document-file' 은 업로드한 필드 이름입니다. 이거 helper로 만들어서 배포할수도 있겠네요 
$uploaded_files = $_FILES;
$uploaded_file_count = count($_FILES['document-file']['name']);

for($i=0; $i<$uploaded_file_count; $i++) {
 if($uploaded_files['document-file']['name'][$i] == null) continue;

 unset($_FILES);

 $_FILES['document-file']['name'] = $uploaded_files['document-file']['name'][$i];
 $_FILES['document-file']['type'] = $uploaded_files['document-file']['type'][$i];
 $_FILES['document-file']['tmp_name'] = $uploaded_files['document-file']['tmp_name'][$i];
 $_FILES['document-file']['error'] = $uploaded_files['document-file']['error'][$i];
 $_FILES['document-file']['size'] = $uploaded_files['document-file']['size'][$i];

 $upload_config = Array(
  'upload_path' => './attachment/temporary/',
  'allowed_types' => 'gif|jpg|jpeg|png',
  'max_size' => '10240'
 );
 $this->upload->initialize($upload_config);
 if( ! $this->upload->do_upload('document-file')) {
  echo $this->upload->display_errors();
 }
}