2014-04-25 80 views
0

我有3種類型的配置用於上傳,事情是當我上傳文件時,它使用與圖像路徑相同的配置來處理所有這些文件,然後它們就會衝突。 這裏是我的代碼:有codeigniter多上傳配置的問題

$config['upload_path'] = './media/content/'; 
       $config['allowed_types'] = 'jpg|jpeg|gif|png'; 
       $config['max_size'] = '100000'; 
       $config['max_width'] = '10024'; 
       $config['max_height'] = '7680'; 
       $config['remove_spaces'] = TRUE; 
       $this->load->library('upload', $config); 
       $this->upload->do_upload("Image"); 
       $ImageData = $this->upload->data(); 
       $Image=$ImageData['file_name']; 
       $ImageFileError=$this->upload->display_errors(); 
       //-------------------------- 
       $config2['image_library'] = 'gd2'; 
       $config2['source_image'] = $_SERVER["DOCUMENT_ROOT"].'/media/content/'.$Image; 
       $config2['create_thumb'] = TRUE; 
       $config3['maintain_ratio'] = TRUE; 
       $config2['width']= 300; 
       $config2['height']= 170; 
       $config2['new_image']= $_SERVER["DOCUMENT_ROOT"].'/media/content/'.'big_thumb_'.$Image; 
       $this->image_lib->initialize($config2); 
       $this->load->library('image_lib', $config2); 
       $this->image_lib->resize(); 
       //--------------- 
       $config3['image_library'] = 'gd2'; 
       $config3['source_image'] = $_SERVER["DOCUMENT_ROOT"].'/media/content/'.$Image; 
       $config3['create_thumb'] = TRUE; 
       $config3['maintain_ratio'] = TRUE; 
       $config3['width']= 268; 
       $config3['height']= 120; 
       $config3['new_image']= $_SERVER["DOCUMENT_ROOT"].'/media/content/'.'small_thumb_'.$Image; 
       $this->image_lib->initialize($config3); 
       $this->load->library('image_lib', $config3); 
       $this->image_lib->resize(); 

if($_FILES['ImageHeader']['size']) 
       { 
        $config8['upload_path'] = './media/content/headers/'; 
        $config8['allowed_types'] = 'jpg|jpeg|gif|png'; 
        $config8['max_size'] = '100000'; 
        $config8['max_width'] = '10024'; 
        $config8['max_height'] = '7680'; 
        $config8['remove_spaces'] = TRUE; 
        //$this->image_lib->initialize($config8); 
        $this->load->library('upload', $config8); 
        $this->upload->do_upload("ImageHeader"); 
        $ImageDataHeader = $this->upload->data(); 
        $ImageHeader=$ImageDataHeader['file_name']; 
        $ImageFileErrorHeader=$this->upload->display_errors(); 
        $config11['image_library'] = 'gd2'; 
        $config11['source_image'] = $_SERVER["DOCUMENT_ROOT"].'/media/content/headers/'.$ImageHeader; 
        $config11['create_thumb'] = false; 
        $config11['maintain_ratio'] = false; 
        $config11['width']= 960; 
        $config11['height']= 240; 
        //$config3['new_image']= $_SERVER["DOCUMENT_ROOT"].'/media/region/'.'small_thumb_'.$ImageHeader; 
        $this->image_lib->initialize($config11); 
        $this->load->library('image_lib', $config11); 
        $this->image_lib->resize(); 
       } 

我不知道爲什麼!我已經uesed initilalze使用新的配置,但仍無法正常工作,並上傳所有在同一文件夾?

回答

0

您只爲主$配置設置$config['upload_path'] = './media/content/';一次,而不再爲其他配置設置。對於每種配置,您還使用$config2['new_image']= $_SERVER["DOCUMENT_ROOT"].'/media/content/'.'big_thumb_'.$Image;,因此您創建的所有文件都將與您聲明的文件夾位於同一文件夾中。

你也應該做到以下幾點加載每個新配置前:

unset($config); // Unloads the previous configuration 
    $this->image_lib->clear(); // Clears the image_lib for the next configuration to be loaded 

然後,你可以加載一個配置: $this->upload->initialize($config);

+0

我有一個頭文件的問題,另一個工作正常 –

+0

製作確定'$ config8 ['upload_path'] ='./media/content/headers /';'具有適當的權限並且是可寫的。 – Skewled

+0

@MasoudMpour是否解決了您的問題? – Skewled