普通网友 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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵