Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter Upload class PDF filetype not allowed

Works locally but on the two servers I've tried the same error message is shown. Using Codeigniter 2.1.3

private function upload_file(){
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'jpg|png|jpeg|gif|pdf';
    $config['max_width']  = '0';
    $config['max_height']  = '0';
    $config['encrypt_name']  = true;
    $this->load->library('upload', $config);
    var_dump($_FILES);
    if ( ! $this->upload->do_upload()){
        $error = array('error' => $this->upload->display_errors());
        var_dump($error);
        die();
        return $error;
    } else {
        $data = array('upload_data' => $this->upload->data());
        var_dump($data);
        die();
        return $data;
    }
}

While doing the var_dump($_FILES); it shows the correct information array(1) { ["userfile"]=> array(5) { ["name"]=> string(8) "0002.pdf" ["type"]=> string(14) "aplication/pdf" ["tmp_name"]=> string(27) "C:\Windows\Temp\php9454.tmp" ["error"]=> int(0) ["size"]=> int(29295) } }

var_dump($error) giving off array(1) { ["error"]=> string(64) " The filetype you are attempting to upload is not allowed. " }

Tested with both a png and jpg and these works marvelously.

The correct mime-types are in the config file config/mimes.php

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

Edit: If it means anything, the local server is a MAC and the two remotes are windows.

like image 858
Bankzilla Avatar asked Sep 03 '26 14:09

Bankzilla


1 Answers

So even though the code is all correct the error is actually on PHP itself. There's a spelling mistake in there mime-types. When var_dump($_FILES) it spitting out ["type"]=> string(14) "aplication/pdf" Note that "application" is spelt wrong.

Checked on workmates machine and his correct, so might be an issue with php >5.3.5

like image 98
Bankzilla Avatar answered Sep 06 '26 04:09

Bankzilla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!