2015-03-31 139 views
0

我必须上传一个带有codeigniter上传库的mp3文件类型。
我使用下面的代码。mp3文件类型在codeigniter中上传

但它不起作用。

类控制器代码:

<?php 
class Upload extends CI_Controller { 
    public function __construct() 
    { 
      parent::__construct(); 
      $this->load->helper(array('form', 'url')); 
    } 

    public function index() 
    { 
      $this->load->view('upload_form', array('error' => ' ')); 
    } 

    public function do_upload() 
    { 
      $config['upload_path']   = './uploads/'; 
      $config['allowed_types']  = 'gif|jpg|png|jpeg|mp3'; 
      $config['max_size']    = 0; 
      $this->load->library('upload', $config); 

      if (! $this->upload->do_upload()) 
      { 
        $error = array('error' => $this->upload->display_errors()); 

        $this->load->view('upload_form', $error); 
      } 
      else 
      { 
        $data = array('upload_data' => $this->upload->data()); 

        $this->load->view('upload_success', $data); 
      } 
    } 
} 
?> 

当文件类型是JPG或者类似的,此代码正确地工作和jpg文件被上载。
但是,当我尝试上传一个mp3文件时,该文件不会上传。
并没有出现任何错误。

我该怎么做?

+2

检查您的php.ini,并确保您的最大上传和发布尺寸大于您要上传的mp3。你的代码看起来很好,我高度怀疑这个问题在你的php.ini – mituw16 2015-03-31 13:29:31

+0

是正确的。谢谢... – 2015-03-31 15:02:44

回答

0

在您的文件mimes.php(application/config/mimes.php)中添加'application/octet-stream',在您想要上传的每个MIME数组中,例如;

OLD: 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3') 
MEW: 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3', 'application/octet-stream')