2017-12-28 42 views
0

私はCodeIgniterに2つのファイルをアップロードできるフォームを用意しています。バックエンドでは、これらのファイルを別のフォルダに保存します。コントローラーでアップロードコードを書きました正しいフォルダにファイルが格納されない

public function upload() 
    { 
     /**Start uploading file**/ 
     $config['upload_path'] = './assets/file/.'; 
     $config['allowed_types'] = 'gif|jpg|png|doc|txt'; 
     $config['max_size'] = 1024 * 8; 
     $config['encrypt_name'] = TRUE; 

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

     if (!$this->upload->do_upload('file')) 
      { 
       $error = array('error' => $this->upload->display_errors()); 
       echo $error; 

      } 
     else 
      { 
       $data = $this->upload->data(); 
       echo $file = $data['file_name']; //name of file 

      } 

     /**End uploading file**/ 

     /**Start uploading img**/ 

     $config2['upload_path'] = './assets/img/.'; 
     $config2['allowed_types'] = 'gif|jpg|png|doc|txt'; 
     $config2['max_size'] = 1024 * 8; 
     $config2['encrypt_name'] = TRUE; 

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

     if (!$this->upload->do_upload('img')) 
      { 
       $error1 = array('error' => $this->upload->display_errors()); 
       echo $error1; 

      } 
     else 
      { 
       $data1 = $this->upload->data(); 
       echo $img = $data1['file_name']; //name of img 

      } 

     /**End uploading img**/ 
    } 

画像はアップロードされていますが、同じフォルダにアップロードされています。誰もが、私はファイルが第二の負荷に別々のフォルダ

+0

画像をされますflolderファイルにアップロードされていますか? –

答えて

2

に保存されて得ることができますどのように、あなたはloadメソッドは、それを初期化しないため、ロードされたライブラリをinitialiazeする必要があります教えてくださいすることができます

$this->upload->initialize($config2); 
+0

ありがとう、それは働いた – user3732711

関連する問題