2017-05-05 2 views
0

Ich versuche, eine Bild-Upload-Codierung mit CodeIgniter zu erstellen und speichern Sie es an meinem Zielort. Diese Codierung funktioniert gut in localhost, aber wenn ich versuchte, diese Codierung nach Cpanel zu laden, gibt es mir einen Fehler.Bild in Code-Signierer hochladen (FEHLER)

Controller-Code:

public function uploadPaid(){ 

    if ($this->input->post()) {      

     $arr = $this->input->post();     
     $this->load->database(); 
     $this->load->model('m_picture'); 
     $this->load->model('m_purchase'); 
     //$this->load->library('my_func'); 
     //$this->load->helper('url'); 
     $this->load->library('upload');      


     $config = array(
       'upload_path' => "./dist/invoice/", 
       'allowed_types' => "gif|jpg|png", 
       'overwrite' => TRUE, 
       'max_size' => "2000", // Can be set to particular file size , here it is 2 MB(2048 Kb) 
       'max_height' => "0", 
       'max_width' => "0", 
       'encrypt_name' => true 
      ); 

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

     $pur_id = $this->input->post('pur_id'); 
     $img_background = $this->input->post('fileImg'); 

     if ($this->upload->do_upload('fileImg')) 
     { 
      $data = $this->upload->data(); 
      $background="dist/invoice/".$data['raw_name'].$data['file_ext']; 
      echo $background; 
      $arr2 = array(         
        "img_url" => $background, 
        "ne_id" => $arr['pur_id']         
       );   

      $this->m_purchase->updateInv(1, $pur_id); 
      $this->m_picture->insert($arr2); 
      $this->session->set_flashdata('success' , '<b>Well done!</b> You successfully send the picture.'); 
      redirect(site_url('purchase_v1/dashboard/page/a29'),'refresh'); 
     } 
     else 
     { 
      echo $this->upload->display_errors(); 
      $this->session->set_flashdata('warning' , '<b>Error!</b> You failed to send the picture.'); 
      redirect(site_url('purchase_v1/dashboard/page/a29'),'refresh'); 
     } 
    }else{ 
     $this->session->set_flashdata('warning' , '<b>Uh Crap!</b> You got Error. The image size is to big'); 
     redirect(site_url('purchase_v1/dashboard/page/a29'),'refresh'); 
    } 
} 

Ansicht Code:

<form action="<?= site_url('purchase_v1/dashboard/uploadPaid'); ?>" method="POST" role="form" enctype="multipart/form-data"> 
    <div class="portlet-body flip-scroll" align="center"> 
     <span style = "color : #b706d6;"><h2><strong>#<?= (110000+$pur_id); ?></strong></h2></span> 
     <div class="form-group"> 
      <div class="fileinput fileinput-new" align="center" data-provides="fileinput"> 
       <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; line-height: 150px;"></div> 
       <div> 
        <span class="btn btn-outline btn-file" style="background-color: #FF5733"> 
         <span class="fileinput-new"> Select image </span> 
         <span class="fileinput-exists"> Change </span> 
         <input type="hidden" value="" name="title"><input type="file" name="fileImg"> 
        </span> 
        <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a> 
       </div> 

       <div class="clearfix">&nbsp;</div> 
       <button type="submit" class="btn btn-primary"><i class="fa fa-upload"> Submit</i></button> 
      </div> 
     </div> 
    </div> 
    <input type="hidden" name="pur_id" id="pur_id" class="form-control" value="<?= $pur_id; ?>"> 
</form> 
+0

lesen Sie bitte: http://stackoverflow.com/a/41132834/2275490 – Vickel

+0

können Sie den Fehler hier einfügen? –

+0

eigentlich, nachdem ich das Bild hochladen, angeblich sollte diese Codierung auf "purchase_v1/dashboard/page/a29" umleiten, ob das Upload-Bild erfolgreich ist oder nicht. Aber es zeigt nur eine leere Seite an, also weiß ich nicht, was für ein Fehler es ist. Vielleicht liegt der Fehler an dieser Codierung, wenn ($ this-> upload-> do_upload ('fileImg')) –

Antwort

0

Sie haben eine falsche Initialisierung der Upload-Bibliothek. Benutze es so. Wenn dies das Problem nicht löst, ist es wahrscheinlich kein Problem beim Hochladen. Es könnte ein Problem an anderer Stelle im Code sein. Der Code selbst ist sehr schlecht.

if ($this->input->post()) { 

     $arr = $this->input->post();     
     $this->load->database(); 
     $this->load->model('m_picture'); 
     $this->load->model('m_purchase'); 
     //$this->load->library('my_func'); 
     //$this->load->helper('url'); 
     $this->load->library('upload'); 

     $config = array(
     'upload_path' => "./dist/invoice/", 
     'allowed_types' => "gif|jpg|png", 
     'overwrite' => TRUE, 
     'max_size' => "2000", // Can be set to particular file size , here it is 2 MB(2048 Kb) 
     'max_height' => "0", 
     'max_width' => "0", 
     'encrypt_name' => true 
     ); 

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

     $pur_id = $this->input->post('pur_id'); 
     $img_background = $this->input->post('fileImg'); 


     if ($this->upload->do_upload('fileImg')) 
     { 
      $data = $this->upload->data(); 
      $background="dist/invoice/".$data['raw_name'].$data['file_ext']; 
      echo $background; 
     $arr2 = array(
        "img_url" => $background, 
        "ne_id" => $arr['pur_id'] 
       );   

     $this->m_purchase->updateInv(1, $pur_id); 
     $this->m_picture->insert($arr2); 
     $this->session->set_flashdata('success' , '<b>Well done!</b> You successfully send the picture.'); 
     redirect(site_url('purchase_v1/dashboard/page/a29'),'refresh'); 
     } 
     else 
     { 
     echo $this->upload->display_errors(); 
     $this->session->set_flashdata('warning' , '<b>Error!</b> You failed to send the picture.'); 
     redirect(site_url('purchase_v1/dashboard/page/a29'),'refresh'); 
     } 

    }else 
    { 
     $this->session->set_flashdata('warning' , '<b>Uh Crap!</b> You got Error. The image size is to big'); 
     redirect(site_url('purchase_v1/dashboard/page/a29'),'refresh'); 
    } 

}