2014-03-02 2 views
0

이미 codeigniter에서 여러 이미지를 업로드하는 코드를 생성했지만 codeigniter 이미지 라이브러리를 사용하여 다른 디렉토리에 업로드 된 이미지의 크기를 크게 생성 할 수 없습니다.다중 이미지 업로드 및 큰 크기 생성

아래 코드를 사용하면 사용자가 여러 이미지를 업로드 한 경우에도 하나의 이미지 만 생성됩니다.

function insert_prod(){ 

    $foldername = $_POST['folder']; 
    $path = './uploads/products/'.$foldername; 

    mkdir($path, 0777, true); 
    mkdir($path.'/zoomimages', 0777, true); 

    $config = array(); 
    $config['upload_path'] = $path; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size']  = '0'; 
    $config['overwrite']  = FALSE; 

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

    $files = $_FILES; 
    $cpt = count($_FILES['userfile']['name']); 
    for($i=0; $i<$cpt; $i++){ 

     $_FILES['userfile']['name']= $files['userfile']['name'][$i]; 
     $_FILES['userfile']['type']= $files['userfile']['type'][$i]; 
     $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i]; 
     $_FILES['userfile']['error']= $files['userfile']['error'][$i]; 
     $_FILES['userfile']['size']= $files['userfile']['size'][$i];  

     $config['file_name'] = 'img_'.$i; 

     $this->upload->initialize($config); 
     $this->upload->do_upload(); 

     $upload_data = array('upload_data' => $this->upload->data()); 
     $full_path = $upload_data['upload_data']['full_path']; 
     $u_data = $upload_data['upload_data']; 
     // var_dump($this->upload->data()); 
     // var_dump($upload_data); 
     echo $cpt; 
     $config1['image_library'] = 'gd2'; 
     $config1['source_image'] = $full_path; 
     $config1['new_image'] =$path.'/zoomimages'; 
     $config1['create_thumb'] = FALSE; 
     $config1['maintain_ratio'] = TRUE; 
     $config1['width'] = 300; 
     $config1['height'] = 300; 

     $this->load->library('image_lib', $config1); 
     $this->image_lib->resize(); 
     $this->image_lib->clear(); 
    } 
} 
+0

모든 업로드마다 입력 이름을 '$ this-> upload-> do_upload ('NAME ');' – Minhaz

+0

'을 확인하십시오. http://stackoverflow.com/questions/11을 확인하십시오. 524356/multiple-files-upload-array-with-codeigniter-2-0 – Minhaz

+0

해당 코드를 사용 중입니다. 여러 이미지를 업로드 할 수 있지만 이미지의 크기를 크게하여 다른 디렉토리에 저장하려고합니다. –

답변

0

당신은 너무 그 루프면이 바깥을 향하게하여 $config1 again

이동 $this->load->library('image_lib');을 설정하지 않는이

그런 $this->load->library('image_lib', $config1);$this->image_lib->initialize($config1); 즉시 추가로드 아직 CodeIgniter의 클래스를 참조 루프 내부 $this->load->library('image_lib', $config1);와 라이브러리입니다로드

관련 문제