2017-11-23 4 views
0

Ich habe ein Problem mit mehreren Dateien mit verschiedenen Namen hochladen und für jeden Bereich Dateinamen vor dem Upload ändern möchten.Codeigniter mehrere Upload mit anderen Bereichsnamen und benennen Sie die Datei vor dem Hochladen

Dies ist HTML-Formular.

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

Dies ist Controller

$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."); 
    } 

Hinweis: Die Bilder in dem Verzeichnis laden werden. Aber ich möchte vor wie „userID_profil.jpg“ und „userID_top.jpg“ hochgeladen jede Datei Dateinamen umbenennen

Antwort

0

ich es gelöst.

$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", "."); 
     } 
    } 
Verwandte Themen