2012-10-10 6 views
0

CI로 여러 이미지를 업로드 중이므로 업로드합니다. 또한 크기를 조정하려고하는데 다음 코드를 사용하여
첫 번째 이미지 만 크기를 조정하고 나머지는 크기를 조정하지 마십시오. 현재 크기로 업로드됩니다. 무엇이 잘못 되었나요?CI 다중 이미지 크기 조정

아무 도움도받지 못했습니다. 정말 감사드립니다.

function doupload() { 

    $path = array(); 
    $count = count($_FILES['userfile']['size']); 

    foreach($_FILES as $key=>$value){ 
     for($n=0; $n<=$count-1; $n++) { 
      $_FILES['userfile']['name']=$value['name'][$n]; 
      $_FILES['userfile']['type'] = $value['type'][$n]; 
      $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$n]; 
      $_FILES['userfile']['error']  = $value['error'][$n]; 
      $_FILES['userfile']['size'] = $value['size'][$n]; 

       $config['upload_path'] = './images'; 
       $config['allowed_types'] = 'gif|jpg|png|jpeg'; 

      $this->load->library('upload', $config); 
      $this->upload->do_upload(); 
      $data = $this->upload->data(); 
      $path[] = $data['full_path']; //contains full path of every image 
     } 
    } 

    foreach($path as $p=>$ath){ 
     $config1 = array(
     'source_image'  => $ath, 
     'new_image'   => './images', 
     'maintain_ration' => true, 
     'overwrite'   => true, 
     'width'    => 600, 
     'height'   => 400 
     ); 

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

    } 


} 

답변

2

첫 번째 부하 image_lib 이미지는 루프에서 초기화 사용하고 생성자에 내 경우 부하 lib에 모든 이미지

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

    foreach($path as $p=>$ath){ 
      $config1 = array(
      'source_image'  => $ath, 
      'new_image'   => './images', 
      'maintain_ration' => true, 
      'overwrite'   => true, 
      'width'    => 600, 
      'height'   => 400 
      ); 

      $this->image_lib->initialize($config); 
      $this->image_lib->resize(); 
      $this->image_lib->clear(); 

     } 
0

CodeIgniter의의 Loader 클래스로드 라이브러리 번만 당신의 foreach 같은 이미지 크기를 조정 여러 번에 너무. 루프에서 라이브러리로드를 이동하고 이미지 조작 라이브러리의 initialize 메소드를 사용하여 모든 크기 조정에 대한 구성을 설정하십시오. 루프 외부

0

에 대한 새로운 설정을 전달하고 사용할 수있는 코드

$config['image_library'] = 'gd2'; 
$config['maintain_ratio'] = FALSE; 
$config['source_image'] = $config['upload_path'].$image_info['file_name']; 

$config['new_image'] = $config['upload_path']."thumb_".$image_info['file_name']; 
$config['width'] = 313; 
$config['height'] = 303; 
$this->image_lib->initialize($config); 
$this->image_lib->resize(); 
$this->image_lib->clear(); 

$config['new_image'] = $config['upload_path']."icon_".$image_info['file_name']; 
$config['width'] = 70; 
$config['height'] = 70; 
$this->image_lib->initialize($config); 
$this->image_lib->resize(); 
$this->image_lib->clear(); 

인덱스를 유지 항상 new_image의 이름은 $config['new_image']