CodeIgniter Upload class PDF filetype not allowed

后端 未结 3 2082
我寻月下人不归
我寻月下人不归 2021-01-14 09:51

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[\'uploa         


        
相关标签:
3条回答
  • 2021-01-14 10:13

    I got the same issue here for some reason I can't upload pdf files a quick troublshooting was to display errors

    $msg = $this->upload->display_errors('<p>', '</p>');
    echo $msg;
    

    I got the error message of invalid file type , so I added anew line of code to display full information about the file to uploaded.

    $msg = $this->upload->display_errors('<p>', '</p>');
    $msg.=print_r($this->upload->data());
    echo $msg;
    

    then I copy the file type to config/mime.php

    'pdf'   =>  array('application/pdf'),
    

    and make sure that the same mime type is used as the mime type of my uploaded file. The funny part was that the error was that in mime.php there was a typo :)

    apostrophe instead of single quote as a result of copy past from internet without paying attention to quotation marks used.

    0 讨论(0)
  • 2021-01-14 10:21

    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

    0 讨论(0)
  • 2021-01-14 10:30

    Instead of

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

    Try this

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

    This works for me

    0 讨论(0)
提交回复
热议问题