douzi8127 2015-03-20 13:18
浏览 75
已采纳

Codeigniter错误:不允许您尝试上传的文件类型

If I upload a csv file, there is no problem on localhost and everything works fine, but when I upload my app on live server and upload a csv file then this error thrown: The filetype you are attempting to upload is not allowed. I am confused as to why this happens. Please help me to solve this.

For my localhost environment, I am using XAMPP and CodeIgniter.

I only want to allow csv file uploads.

  • 写回答

2条回答 默认 最新

  • dounang1974 2015-03-23 21:56
    关注

    check 2 things:

    First: in your upload controller: make sure to set the correct allowed types

    $config['allowed_types'] = 'csv';
    $this->load->library('upload', $config);
    

    Second: update the array $mimes in your config/mimes.php:

    'csv'   =>  array('application/vnd.ms-excel', 
               'text/anytext', 
               'text/plain', 
               'text/x-comma-separated-values', 
               'text/comma-separated-values', 
               'application/octet-stream', 
               'application/vnd.ms-excel', 
               'application/x-csv', 
               'text/x-csv', 
               'text/csv', 
               'application/csv', 
               'application/excel', 
               'application/vnd.msexcel')
    

    UPDATE:

    you could use print_r($_FILES) in your upload controller to check for the mime-type missing. this would output something like:

    [userfile] => Array
        (
            [name] => teste1.csv
            [type] => application/vnd.ms-excel
            [tmp_name] => C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\binaries\tmp\php8BFD.tmp
            [error] => 0
            [size] => 7880
        )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化