2011-01-04 4 views
0

Ich habe das gleiche Problem. Andere Dateien doc, xls hochgeladen fein. aber das Hochladen von PDF gibt einen Fehler. „Der Dateityp Sie versuchen, ist zum Hochladen nicht erlaubt.“ in config/mimnes.php ich habe:Warum schlägt der PDF-Upload auf Codeigniter 1.7.2 fehl?

'pdf' => array('application/pdf', 'application/x-download', 'application/download'), 

in Controllern ich habe:

function upload_file($type, $upload_type) 
{ 
    $this->load->library('upload'); 
    //upload file 
    switch($upload_type){ 
     case "image": 
      $config['upload_path'] = './uploads/'; 
      $config['allowed_types'] = 'gif|jpg|jpg|png|pdf'; 
      $config['max_size'] = '3000'; 
      $config['max_width'] = '3224'; 
      $config['max_height'] = '1268'; 
     break; 
     case "doc": 
      $config['upload_path'] = './uploads/pages/doc/'; 
      $config['allowed_types'] = 'pdf|doc|docx|xls|ppt'; 
      $config['max_size'] = '3000'; 
      $config['encrypt_name'] = TRUE; 
     break; 
    } 
    foreach($_FILES as $key => $value) 
    { 
     if(! empty($value['name'])) 
     { 
       $this->upload->initialize($config); 

       if (! $this->upload->do_upload($key)) 
       { 
       $errors = array('error' => $this->upload->display_errors()); 
       $this->session->set_flashdata('flashError', $errors); 

       } 
       else 
       { 
        $this->page_model->process_file($type, $upload_type); 
       } 
     } 
    } 
} 

jede Hilfe spürbar sein wird.

Antwort

0

Entfernen Sie diese Zeile:

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

Dann fügen Sie diese Zeile nach dem Ende der Schalterblock und vor foreach Block

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

Sie die Upload-Bibliothek geladen und dann Config-Werte einstellen, die nicht hat bewirken.

Ihre modifizierte Funktion sollte wie folgt aussehen:

function upload_file($type, $upload_type) 
{ 
    //upload file 
    switch($upload_type){ 
     case "image": 
      $config['upload_path'] = './uploads/'; 
      $config['allowed_types'] = 'gif|jpg|jpg|png|pdf'; 
      $config['max_size'] = '3000'; 
      $config['max_width'] = '3224'; 
      $config['max_height'] = '1268'; 
     break; 
     case "doc": 
      $config['upload_path'] = './uploads/pages/doc/'; 
      $config['allowed_types'] = 'pdf|doc|docx|xls|ppt'; 
      $config['max_size'] = '3000'; 
      $config['encrypt_name'] = TRUE; 
     break; 
    } 

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

    foreach($_FILES as $key => $value) 
    { 
     if(! empty($value['name'])) 
     { 
       $this->upload->initialize($config); 

       if (! $this->upload->do_upload($key)) 
       { 
       $errors = array('error' => $this->upload->display_errors()); 
       $this->session->set_flashdata('flashError', $errors); 

       } 
       else 
       { 
        $this->page_model->process_file($type, $upload_type); 
       } 
     } 
    } 
} 
+0

i Config wie $ initialisierte this-> upload-> initialize ($ config); es ist nicht nötig, zweimal dasselbe zu tun. – kamal

+0

Sind Sie sicher, dass Sie den richtigen Wert in $ upload_type haben? –

+0

ya $ upload_type ist korrekt. aber heute, was ich herausgefunden habe, ist: ich bin in der Lage, Datei alternativ hochzuladen. wenn ich eine doc-datei und eine pdf-datei hochlade, werden beide hochgeladen. und wenn ich pdf-Datei nur hochladen es nicht. was könnte der Grund sein. – kamal

0

Sind Sie FireFox verwenden? Ich hatte das gleiche Problem, entstanden von FF. Der gemeldete mimetype ist application/binary, also können Sie das in mimes.php

chagen, das sollte das Problem lösen.

+0

überhaupt nicht. Es funktioniert gut in IE aber nicht in Firefox. Ich benutze 3.6.13 – kamal

+0

, um zu sehen, was vorverarbeitet wird, können Sie eine print_r ($ _ FILES) hinzufügen und die Ausgabe kopieren? –

+0

Hier ist mein: Array ([nuevoarchivo] => Array ([name] => 110_2008.pdf [type] => application/pdf [tmp_name] =>/tmp/phpDLUXpE [Fehler] => 0 [size] => 30680)) –

1

Ich hatte das gleiche Problem, aber herausgefunden, dass einige PDF-Dateien als Typ Anwendung/Oktettstream in FireFox gesendet werden. Ich weiß nicht warum. Aber versuchen Sie, mimetype.php zu öffnen, fügen Sie es zum mimetype Array von pdf-Datei wie folgt hinzu:

'pdf' => array ('application/pdf', 'application/x-download', 'application/binary' 'application/octet-stream'),

+0

danke Mann das war es – mokNathal

Verwandte Themen