개발 Q&A

제목 복수개 파일 업로드 후, 업로드한 파일정보 db테이블에 insert 처리
카테고리 PHP
글쓴이 그동안 작성시각 2019/06/20 00:32:05
댓글 : 5 추천 : 0 스크랩 : 1 조회수 : 8280   RSS

복수개 파일 업로드 후(서버에 파일 올리는데 성공), 

파일 업로드된 개수만큼 foreach해서 

- 업로드된 경로

- 업로드된 파일명

를 DB에 저장하려고 합니다. 

 

$upfile_info = $this->upload->data();        //[1] 복수개 파일업로드 했을경우 어떻게 해야 할까요? 배열로 돌림? 잘안되네요;;

foreach($upfile_info as $key => $value)      //[2] 업로드한 이미지 수 만큼 foreach하고 싶습니다 

'portfolio_img_name' => $upfile_info['file_name'] ,      //[3] foreach된 이미지명 대입을 어떻게 해야 할까요?

 



[컨트롤러]

//$this->upload->data는 업로드된 파일의 다양한 정보를 갖고 있다
$upfile_info = $this->upload->data();	                                //[1] 복수개 파일업로드 했을경우 어떻게 해야 하는지요

//포트폴리오 이미지
//foreach($upfile_info as $key => $value)                               //[2] 업로드한 이미지 수 만큼 foreach하고 싶습니다               
//{
    $data = array(                                          //db에 요청할 값을 배열로 만듬. db필드명 => 수정값 
	  'db_table_name' => 'profile_portfolio_img' ,                      //업데이트할 DB 테이블명
	  'pport_id' => $result ,
	  'portfolio_img_path' => $upfile_info['file_path'] ,               
	  'portfolio_img_name' => $upfile_info['file_name'] ,               //[3] foreach된 이미지명 대입을 어떻게 해야 할까요 
      'created_by' => $this->session->userdata('user_nm') ,                             
      'created_ip' => $this->session->userdata('ip_address')                                       
    );
    $result = $this->profile_portfolio_img_m->my_profile_add_06_insert($data);            

 

 다음글 목록 필터 기능을 만들고 있는데요, 뷰 목록의 게시물이... (7)
 이전글 ftp 업로드시 ftp_connect, ftp_logi... (1)

댓글

kaido / 2019/06/20 09:39:26 / 추천 0

복수 업로드는 upload 라이브러리 그대로 사용하시면 안됩니다 ㅎㅎ

우선 복수 업로드 기존 php 코드부터 분석해 보시는게 좋습니다. 

이부분은 가능하면 꼭 참고해 보시길 바랍니다.

 

사실 복수 업로드가 별거 없습니다

복수일경우 print_r 찍어보시면 복수 배열로 넘어옵니다. 

ci upload 는 단일 업로드를 기준으로 만들어져서 별도의 로직처리가 필요합니다.

codeigniter multy upload 찾아보시면 커스텀 라이브러리가 많이 돌아다닙니다. 그걸 참고하시는게 더 빠릅니다.

그동안 / 2019/06/20 10:53:33 / 추천 0

kaido님, 일단 서버에 복수파일 업로드는 구현된 상황인데요,,,

복수업로드 된 파일정보를 db 테이블에 insert하는 부분에서 막혀서 질문 드렸습니다. 

질문 글의 [1][2][3]번 부분에 대해 가르침을 좀 부탁 ㅠㅠ 

 

kaido / 2019/06/20 11:09:05 / 추천 0
/** 업로드 옵션 */
function set_upload_options()
{
    //upload an image options
    $config = array();
    $config['upload_path'] = FCPATH . 'uploads/product/temp/';
    //$config['allowed_types'] = 'gif|jpg|png';
    $config['allowed_types'] = '*';
    $config['max_size'] = '51200'; //50MB  ... 단위는 KB
    $config['overwrite'] = false;
    $config['max_width'] = 0; //무제한
    $config['max_height'] = 0; //0 무제한
    return $config;
}

/** 멀티 형태 업로드 */
function _do_upload_multi($target_file, $insertId = null)
{
    $this->load->library('upload');    
    $files = $_FILES;
    $cpt = count($_FILES["$target_file"]['name']);
    $target_file_temp = $target_file . "_temp";
    for ($i = 0; $i < $cpt; $i++) {
        $_FILES["$target_file_temp"]['name'] = $files["$target_file"]['name'][$i];
        $_FILES["$target_file_temp"]['type'] = $files["$target_file"]['type'][$i];
        $_FILES["$target_file_temp"]['tmp_name'] = $files["$target_file"]['tmp_name'][$i];
        $_FILES["$target_file_temp"]['error'] = $files["$target_file"]['error'][$i];
        $_FILES["$target_file_temp"]['size'] = $files["$target_file"]['size'][$i];

        $this->upload->initialize($this->set_upload_options());
        if (!$this->upload->do_upload($target_file_temp)) {
            $error = array('error' => $this->upload->display_errors());
            echo '<xmp>'; print_r($error); echo '</xmp>';            
            return false;
        } else {            
            $data = array('upload_data' => $this->upload->data());
            // $data["upload_data"]["file_name"]; 
            // .....
            // $data["upload_data"]["file_size"]; 
            echo '<xmp>'; print_r($data); echo '</xmp>';
        }
    }    
}
가장 기본 형태입니다. 나머지는 그동안님의 센스 있는 코딩이 필요합니다 !
그동안 / 2019/06/20 12:21:02 / 추천 0

한가지만 더 물어볼께요~~;;

파일 2개 서버에 업로드된 것 확인하고. 아래 값 찍어보면

$data = array('upload_data' => $this->upload->data()); 

 

이렇게 1개 파일만 확인 됩니다. $data = array     <=== 왜 array 했는데 1개만 확인될까요???

<xmp>Array
(
    [data] => Array
        (
            [file_name] => 31ac0c76ddca2a427fe22050c6a07db0.PNG
            [file_type] => image/png
            [file_path] => /kss3594/www/uploads/portfolio_img/
            [full_path] => /kss3594/www/uploads/portfolio_img/31ac0c76ddca2a427fe22050c6a07db0.PNG
            [raw_name] => 31ac0c76ddca2a427fe22050c6a07db0
            [orig_name] => 캡처.PNG
            [client_name] => 캡처.PNG
            [file_ext] => .PNG
            [file_size] => 31.85
            [is_image] => 1
            [image_width] => 107
            [image_height] => 135
            [image_type] => png
            [image_size_str] => width="107" height="135"
        )

)
</xmp>

   

kaido / 2019/06/20 13:43:34 / 추천 0

같은 $data 안에 2번 들어간것 아닌가요?

$data[1]

$data[2]

이런 형태로 각각 나눠서 넣으시면 잡힐것 같습니다