普通网友 2017-06-17 07:05
浏览 130
已采纳

在Codeigniter 3中上传文件

i try to upalod wav file using codeigniter. But i have get this error message;
The filetype you are attempting to upload is not allowed.

Code Shown below:

    $config['upload_path'] = getwdir() . 'voices/';
    $config['allowed_types'] = 'wav|mp3';
    $config['max_size'] = 2800000;
    $config['file_name'] = rand();
    $this->upload->initialize($config);
    var_dump($config);
    if ($this->upload->do_upload('file')) {
        var_dump('uploaded');
    }else{
        var_dump($this->upload->display_errors());
    }

var_dump($_FILES['file']);

  array (size=1)
 'file' => 
    array (size=5)
      'name' => string 'blob' (length=4)
      'type' => string 'audio/wav' (length=9)
      'tmp_name' => string '/tmp/phpe2SQi5' (length=14)
      'error' => int 0
      'size' => int 98348
  • 写回答

2条回答 默认 最新

  • dongmi1864 2017-06-17 21:19
    关注

    This will help you

    View HTML

    <form method="POST" enctype="multipart/form-data" action="/your_controller/do_upload" >
    <input type="file" name="fileForUpload">
    <input type="submit" value="Upload">
    

    Controller

        <?php 
    public function do_upload(){
        $config = array();
        $config['upload_path'] = './path_from_root_to_dir/';
        $config['allowed_types'] = '*'; //'gif|jpg|png';
        $config['encrypt_name']  = TRUE;
        //$config['max_size'] = 100;
        //$config['max_width'] = 1024;
        //$config['max_height'] = 768;
        $this->load->library('upload',$config);
        if ( ! $this->upload->do_upload('fileForUpload')) {
            $error = array('error' => $this->upload->display_errors());
            //Action, in case file upload failed
        } else {
            //Action, after file successfully uploaded
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化