2017-11-23 6 views
0

アップロードする前に、異なるエリア名で複数のファイルをアップロードする際に問題があり、すべてのファイル名を変更する必要があります。異なる地域名の複数のアップロードとアップロード前にファイルの名前を変更

これはHTML形式です。

<input type="file" placeholder="" name="profilPic"/> 
<input type="file" placeholder="" name="topPic"/> 

これは、コントローラ

$config['upload_path']   = './uploads/'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['max_size']    = 100; 
    $config['max_width']   = 1024; 
    $config['max_height']   = 768; 
    //$config['file_name']   = $this->session->sersession["id"]; 
    $this->load->library('upload', $config); 
    $profilPic = $this->upload->do_upload('profilPic'); 
    if (!$profilPic){ 
     $error = array('error' => $this->upload->display_errors()); 
     $this->session->set_flashdata("error", "profil pic was not uploaded= "); 
    }else{ 
     $data = array('upload_data' => $this->upload->data()); 
     $this->session->set_flashdata("success", "profil picture was uploaded."); 
    } 
    $topPic = $this->upload->do_upload('topPic'); 
    if (!$topPic){ 
      $error = array('error' => $this->upload->display_errors()); 
      $this->session->set_flashdata("error", "top pic was not uploaded"); 

    }else{ 
     $data = array('upload_data' => $this->upload->data()); 
     $this->session->set_flashdata("success", "this picture was uploaded."); 
    } 

。注:画像は、ディレクトリにアップロードされています。しかし、私はあなたがまた、もちろん

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

を使用して、第2のファイルアップロードの前に$config['file_name']を設定することができ、すべてのファイルのファイル名を変更したいの前に「userID_profil.jpg」と「userID_top.jpg」のようにアップロード

答えて

0

私はそれを解決しました。

$config['upload_path']   = './uploads/'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['max_size']    = 100; 
    $config['max_width']   = 1024; 
    $config['max_height']   = 768; 
    if($_FILES["profilPic"]["name"]){ 
     $config["file_name"] = $this->session->usersession["id"]."_profil.jpg"; 
     $this->load->library('upload', $config); 
     $profilPic = $this->upload->do_upload('profilPic'); 
     if (!$profilPic){ 
      $error = array('error' => $this->upload->display_errors()); 
      $this->session->set_flashdata("error", "."); 
     }else{ 
      $profilPic = $this->upload->data("file_name"); 
      $data = array('upload_data' => $this->upload->data()); 
      $this->session->set_flashdata("success", "."); 
     } 
    } 

    if($_FILES["topPic"]["name"]){ 
     $config["file_name"] = $this->session->usersession["id"]."_top.jpg"; 
     if($_FILES["profilPic"]["name"]){ 
      $this->upload->initialize($config); 
     }else{ 
      $this->loadl->library('upload', $config); 
     } 
     $topPic = $this->upload->do_upload('topPic'); 
     if (!$topPic){ 
      $error = array('error' => $this->upload->display_errors()); 
      $this->session->set_flashdata("error", ""); 
     }else{ 
      $topPic = $this->upload->data("file_name"); 
      $data = array('upload_data' => $this->upload->data()); 
      $this->session->set_flashdata("success", "."); 
     } 
    } 
関連する問題