Upload audio error pada codeigniter

Saya ingin mengupload file audio ke server dengan menggunakan codeigniter, file yang diijinkan untuk diupload hanya boleh berekstensi mp3 dan m4a. Tapi saat upload muncul error : the filetype you are attempting to upload is not allowed.

public function _do_upload_msc($name){
    $config['upload_path']          = DEFAULT_UPLOAD_MSC;
    $config['allowed_types']        = 'm4a|mp3';
    $config['max_size']             = 50000;
    $config['file_name']            = $name;

      $this->load->library('upload', $config);
      if(!$this->upload->do_upload('file')) //upload and validate
        {
            $data['inputerror'][] = 'file';
      	    $data['error_string'][] = 'Upload error: '.$this->upload->display_errors('',''); //show ajax error
      	    $data['status'] = FALSE;
      	    echo json_encode($data);
      	    exit();
	 }
	return $this->upload->data('file_name');
  }

saat saya menggunakan var_dump hasil arraynya seperti ini:

array (size=5)
      'name' => string 'See U Later.m4a' (length=15)
      'type' => string 'audio/x-m4a' (length=11)
      'tmp_name' => string 'C:\Program Files (x86)\Ampps\tmp\php20AC.tmp' (length=44)
      'error' => int 0
      'size' => int 2425205

kalau pakai print_r :

Array
(
    [file_name] => See U Later.m4a
    [file_type] => video/mp4
    [file_path] => C:/Program Files (x86)/Ampps/www/upload/music/
    [full_path] => C:/Program Files (x86)/Ampps/www/upload/music/See U Later.m4a
    [raw_name] => See U Later
    [orig_name] =>
    [client_name] => See U Later.m4a
    [file_ext] => .m4a
    [file_size] => 2425205
    [is_image] =>
    [image_width] =>
    [image_height] =>
    [image_type] =>
    [image_size_str] =>
)

Kira-kira apa masalahnya ya? terimakasih.

avatar DennyKurniawan
@DennyKurniawan

62 Kontribusi 22 Poin

Diperbarui 5 tahun yang lalu

1 Jawaban:

Jawaban Terpilih

Mungkin filenya gan dari [file_type] => video/mp4 bukan m4a (hasil convert dia mungkin)

Alternatif lain coba cek ada file mimes.php di bawah config, tambahakan mime type array sesuai yang dimau, <a href='https://www.lifewire.com/audio-file-mime-types-3469485 '>contoh list disini</a>

Conthon untuk mp3:

<pre> 'mp3' =&gt; array('audio/mpeg','audio/mpeg3','audio/mpg','audio/x-mpeg','audio/mp3','application/force-download','application/octet-stream'), </pre>

avatar hilmanski
@hilmanski

2686 Kontribusi 2135 Poin

Dipost 5 tahun yang lalu

Tanggapan

Bekerja seperti sihir. Terimakasih. :)

mantapjiwa

Login untuk ikut Jawaban