普通网友 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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog