CI 묻고 답하기

제목 업로드 하는데 Cannot modify header information 에러가 뜨네여.
글쓴이 하늘우러름 작성시각 2016/04/05 12:17:26
댓글 : 4 추천 : 0 스크랩 : 0 조회수 : 13169   RSS

별다른 작업을 하진 않았는데 에러가 뜹니다.

이미지 파일 업로드할 때 잘 되다가 갑자기 안되네요.

 

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/mejsy81/public_html/application/controllers/center.php:1111)

Filename: helpers/url_helper.php

Line Number: 542

 

------- center.php 1111 부분 ----------

for($i=0; $i<$Cnts; $i++) {                                

     if($uploaded_files['userfile']['name'][$i] == null) continue;                             

     unset($_FILES);                   

     $_FILES['userfile']['name']     = $uploaded_files['userfile']['rename'][$i];                

     $_FILES['userfile']['type']     = $uploaded_files['userfile']['type'][$i];                

     $_FILES['userfile']['tmp_name'] = $uploaded_files['userfile']['tmp_name'][$i];                

     $_FILES['userfile']['error']    = $uploaded_files['userfile']['error'][$i];                

     $_FILES['userfile']['size']     = $uploaded_files['userfile']['size'][$i];

     //$imgName[$i] = $_FILES['upfile']['rename'];                               

     $config['upload_path'] = './include/images/products/';               

     $config['allowed_types'] = 'gif|jpg|png';               

     $config['max_size'] = '0';                               

     $this->load->library('upload', $config);

     if( ! $this->upload->do_upload('userfile')) {                    

          echo $this->upload->display_errors();         // <-- 1111 라인       

     }                          

}

혹시 해결방법좀 알 수 있을까요?

이 부분에서 이미지 업로드가 안되네요.

 

 

 다음글 액티브 레코드 사용에 관하여 (5)
 이전글 자바스크립트 함수 -> PHP 함수 변환 문제 (4)

댓글

한대승(불의회상) / 2016/04/05 12:31:06 / 추천 0
echo $this->upload->display_errors();

이 부분을 아래 처럼 바꿔 보세요.

$this->output->set_output($this->upload->display_errors());

 

하늘우러름 / 2016/04/05 14:09:18 / 추천 0

보내주신 부분 수정하니까 에러는 안뜹니다. 감사합니다.

하나만 더 여쭤볼게여.

이미지 파일이 업로드가 되질 않네요.

제가 아무리 봐도 이유를 못 찾겠어요.

혹시 오류를 찾을 수 있을까요?

====================== 해당소스 =========================

        if($_POST){
            $product_name = $this->input->post('product_name');
            $price = $this->input->post('price');
            $site = $this->input->post('site');
            $category = $this->input->post('category');
            $recommend = $this->input->post('recommend');
            
            $data['addr'] = base_url().$main."center/management/";
            $addr = base_url().$main."center/product_write2/";

           foreach ($_FILES["userfile"]["error"] as $key => $error) {
               if ($error == UPLOAD_ERR_OK) {
                   $tmp_name = $_FILES["userfile"]["tmp_name"][$key]; // 업로드된 임시 파일
                   $name = $_FILES["userfile"]["name"][$key]; // 원본 파일명
                   $rename = $this->getImageName($name);
                   $_FILES["userfile"]["rename"][$key] = $rename;            
               }
           }
           
            $uploaded_files = $_FILES;
            $uploaded_file_count = count($_FILES['userfile']['name']);
            $Temp = $_FILES['userfile']['name'];
            $reName = $_FILES['userfile']['rename'];

            $images = array();
            for($i=0; $i<4; $i++){
                if($Temp[$i] !== "") {
                    $newName = $reName[$i];
                    array_push($images, $newName);
                } else {
                }
            }

            $Cnts = count($images);

            switch($Cnts) {
                case "1":
                    $img1 = $images[0];
                    $img2 = "";
                    $img3 = "";
                    $img4 = "";
                break;
                case "2":
                    $img1 = $images[0];
                    $img2 = $images[1];
                    $img3 = "";
                    $img4 = "";
                break;
                case "3":
                    $img1 = $images[0];
                    $img2 = $images[1];
                    $img3 = $images[2];
                    $img4 = "";
                break;
                case "4":
                    $img1 = $images[0];
                    $img2 = $images[1];
                    $img3 = $images[2];
                    $img4 = $images[3];
                break;
                default :
                break;
            }

            for($i=0; $i<$Cnts; $i++) {
                
                if($uploaded_files['userfile']['name'][$i] == null) continue;
             
                unset($_FILES);
   
                $_FILES['userfile']['name']     = $uploaded_files['userfile']['rename'][$i];
                $_FILES['userfile']['type']     = $uploaded_files['userfile']['type'][$i];
                $_FILES['userfile']['tmp_name'] = $uploaded_files['userfile']['tmp_name'][$i];
                $_FILES['userfile']['error']    = $uploaded_files['userfile']['error'][$i];
                $_FILES['userfile']['size']     = $uploaded_files['userfile']['size'][$i];
                
                //print_r($_FILES['userfile']['name']); exit;
                //$imgName[$i] = $_FILES['upfile']['rename'];
                
                $config['upload_path'] = './include/images/products/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '0';
                
                $this->load->library('upload', $config);

                if( ! $this->upload->do_upload('userfile')) {
                    //echo $this->upload->display_errors();
                    $this->output->set_output($this->upload->display_errors());
                }
                
            }

            $this->center_m->product_insert($site, $category, $product_name, $recommend, $img1, $img2, $img3, $img4, $category, $price);
            $num = $this->center_m->get_maxNum();
            redirect($addr.$num);

 

이미지 업로드가 안되네여.. ㅠ.ㅠ

kaido / 2016/04/05 14:39:52 / 추천 0

에러가 안 나오고 파일도 정상인데 업로드가 안된다면 90% 이상 폴더 권한 문제 입니다.

퍼미션 으로 검색해 보세요.

하늘우러름 / 2016/04/05 18:33:01 / 추천 0

kaido님 말씀이 맞네요. 권한 설정을 바꾸니까 업로드가 잘 되네요. 

불의화상님, kaido님 감사합니다. ^^