개발 Q&A

제목 이미지 첨부가 포함된 수정 페이지에서...
카테고리 PHP
글쓴이 신일 작성시각 2019/10/16 10:06:58
댓글 : 7 추천 : 0 스크랩 : 0 조회수 : 11054   RSS

안녕하십니까, 어제 문의 답변 받아서 코드를 수정했는데, 아무리봐도 문제가 없는거 같은데 에러가 발생합니다.

아래 코드는 이력서 수정 컨트롤러와 모델 인데요.  수정 페이지라서 이력서 사진 첨부가 선택 항목입니다.    

사진을 수정하면 정상적으로 변경이 되는데요, 수정하지 않고 저장하면 500 에러가 발생합니다;;

혹시 아시는 분 계실까요?

--- 뷰에서 값 넘김 ---

------컨트롤러-------

public function my_profile_edit_01()                                                        
{  
	$this->form_validation->set_rules('introduce', '한줄소개', 'required');
	$this->form_validation->set_rules('job_type', '직종', 'required');

	if ( $this->form_validation->run() == TRUE )                                                   
	{  
		if( isset($_FILES) )                                               //프로필 사진 값이 넘어왔으면
		{	
			$config = array(
				'upload_path' => 'uploads/profile_img/',
				'allowed_types' => 'gif|jpg|png',
				'encrypt_name' => TRUE,                                                                    
				'max_size' => '1000'
			); 
			$this->load->library('upload', $config);

			if (!$this->upload->do_upload())                                                               
			{
				$error = array('error' => $this->display_errors());                                        
                alert($error);                                                                             
			}
			else                                                                                           
			{
                $upfile_info = $this->upload->data();                                                      
                
                //저장한다
			    $data = array(                                                                              
				  'db_table_name' => 'profile_basic' ,                                                     
			      'pbs_id' => $this->input->post('pbs_id', TRUE) ,                                         
				  'profile_img_path' => $upfile_info['file_path'] ,                                        
				  'profile_img_name' => $upfile_info['file_name'] ,                                                         
				  'introduce' => $this->input->post('introduce', TRUE) ,                                   
				  'job_type' => $this->input->post('job_type', TRUE) ,                                                
			    );
	            $result = $this->profile_basic_m->my_profile_edit_01_update($data);                        
		        echo json_encode($result); 
		    }
		}
		else                                                                 //프로필 사진 값이 안 넘어왔으면
		{  
            //저장한다
		    $data = array(                                                                                 
			  'db_table_name' => 'profile_basic' ,                                                         
			  'pbs_id' => $this->input->post('pbs_id', TRUE) ,                                                            
			  'introduce' => $this->input->post('introduce', TRUE) ,                                       
			  'job_type' => $this->input->post('job_type', TRUE) ,                                                     
		    );
            $result = $this->profile_basic_m->my_profile_edit_01_update($data);                            
	        echo json_encode($result); 
		}
	} 
	else                                                                                                   
	{		      
	    $makeing_data = array('edit_pbs_id' => $pbs_id);                                                   
		$this->session->set_userdata($makeing_data);  
	}          
}




----모델---
function my_profile_edit_01_update($array)
{                
    if( $array['profile_img_name'] )                                      //프로필 파일명 값이 넘어 왔으면 
    {
        $update_array = array ( 'profile_img_name' => $array['profile_img_name'], 'profile_img_path' => $array['profile_img_path'], 'introduce' => $array['introduce'], 'job_type' => $array['job_type'] );
    }
    else                                                                  //프로필 파일명 값이 안 넘어 왔으면
    {
        $update_array = array ( 'introduce' => $array['introduce'], 'job_type' => $array['job_type'] );            
    }
    $where = array('pbs_id' => $array['pbs_id'] );                                    
    $result = $this->db->update( $array['db_table_name'], $update_array, $where );      
    return $result;                                                                     
}

 

 다음글 password_hash 비교연산 가능여부 (3)
 이전글 비주얼 스튜디오 코드를 사용 하는데 프로그램 작동이 안... (3)

댓글

변종원(웅파) / 2019/10/16 10:19:52 / 추천 0
웹서버 로그랑 ci 로그 보세요.
신일 / 2019/10/16 17:42:52 / 추천 0

 

DEBUG - 2019-10-16 17:37:19 --> Language file loaded: language/korean/upload_lang.php
ERROR - 2019-10-16 17:37:19 --> 업로드할 파일을 선택하지 않았습니다.

업로드할 파일을 선택하지 않았다고 하는데;;

아래 부분이 실행되는데 왜 이런 메세지가 나올까요;;

 

        else      //프로필 사진 값이 안 넘어왔으면
        { 
            //저장한다
            $data = array(                                                                                
              'db_table_name' => 'profile_basic' ,                                                        
              'pbs_id' => $this->input->post('pbs_id', TRUE) ,                                                           
              'introduce' => $this->input->post('introduce', TRUE) ,                                      
              'job_type' => $this->input->post('job_type', TRUE) ,                                                    
            );
            $result = $this->profile_basic_m->my_profile_edit_01_update($data);                           
            echo json_encode($result);
        }

 

엽토군 / 2019/10/16 17:52:39 / 추천 0
isset() 말고 !empty() 로 잡아보세요.
신일 / 2019/10/16 20:42:48 / 추천 0

아~ 엽토군님 말대로  !empty($_FILES) 로 잡으니까 되네요;; 감사합니다.

isset($_FILES ,  !empty($_FILES)  ,  $_FILES    <====이 3개가 모두 동일한거 아닌가요???? 어떤 차이가 있는지요?

kaido / 2019/10/17 09:41:32 / 추천 0

isset 은 배열이 있는지 확인입니다.

정확히는 배열공간이 있는지 확인입니다.

$arr['a'] = null;

배열의 값이 아닌 $arr 의 'a' 이라는 배열 공간 체크여부입니다.

 

!empty 는 값이 존재 하는지 체크입니다.

!= null 하고 같은 의미입니다.  (!== null은 또 다른 의미입니다.)

if($_FILES)

true false 체크입니다.

값이 있으면 true 없으면 false 인데, 종합적 판단입니다.

blooen 형태 판단도 하고, 1,0 을 blooen 판단도 하고, 텍스트나 숫자가 들어있으면 true 없으면 false 형태로 체크입니다.

 

 

신일 / 2019/10/18 14:03:16 / 추천 0
Kaido님 가르쳐줘서 감사합니다^^
쌈닭 / 2019/10/21 15:38:39 / 추천 0

@신일

https://sckim70.tistory.com/14

여기 한번 보세요.