Welcome Guest, Not a member yet? Register   Sign In
Mp3 Mime-type?
#1

[eluser]markanderson993[/eluser]
Hello there codeIgniter experts, I am having difficulty with my mp3 mime-type. Some users can upload mp3 files and others can't which leads me to believe that a problem exists with my mime-types for mp3 files. Can you check and make sure I have the correct information?

This is what I have.

Code:
'mp3'    => array('audio/mpeg','audio/mpeg','audio/mpg','audio/x-mpeg','audio/mp3','application/force-download','application/octet-stream'),

If you see something I'm missing please respond!

Thank you!
- Pianoman993
#2

[eluser]pistolPete[/eluser]
You could setup a test upload page for those users in order to get the mime type their browser sent.

audio/mpeg appears twice in your list, but that shouldn't cause any trouble.

Try adding the following (just copied from a google result):
- audio/mpeg3
- audio/x-mpeg-3
- video/mpeg
- video/x-mpeg
#3

[eluser]TheFuzzy0ne[/eluser]
Great idea! If the file upload fails, see if you can log the mime type (not sure how easy this would be).
#4

[eluser]markanderson993[/eluser]
Hmm... Pistol, I added your mime-tags and deleted the duplicate I had in the array. I'll report back if the problem is solved.
#5

[eluser]TheFuzzy0ne[/eluser]
For the cause:

./system/application/libraries/MY_Upload.php
Code:
<?php

class MY_Upload extends CI_Upload {
    
    function is_allowed_filetype()
    {
        if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
        {
            $this->set_error('upload_no_file_types');
            return FALSE;
        }
                
        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));
        
            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }    
            }        
        }
        # START EDIT #
        $log_file = BASEPATH . 'logs/unknown_mimes.log';
        $file_type = $this->file_type;
        echo $file_type . '<br />';
        if (file_exists($log_file))
        {
            $file = file($log_file);
            
            if ( ! $file_type)
            {
                $file_type = 'No Mime Type!';
            }
            else if ( ! in_array($file_type, $file))
            {
                $file[] = $file_type;
            }
            $file_type = implode("\n", $file);
            echo $file_type;
        }
        
        file_put_contents($log_file, $file_type);
        
        # END EDIT #
        return FALSE;
    }
}

// End of file: MY_Upload.php
// Location: ./system/application/libraries/MY_Upload.php
// End of file: MY_Upload.php
// Location: ./system/application/libraries/MY_Upload.php
The above code is tested and working.

This should log any unrecognised mime types to ./system/logs/unknown_mimes.log. It should only log any one mime once, so you won't have to sift through lots of lines.
#6

[eluser]markanderson993[/eluser]
Fuzzy you never fail to impress me. Dang.
#7

[eluser]markanderson993[/eluser]
When running the code I just get one error

Quote:Fatal error: Call to undefined function exists() in /home/.../application/libraries/MY_Upload.php on line 35

Any idea how to fix that?
#8

[eluser]TheFuzzy0ne[/eluser]
D'oh! Should be "file_exists". I've corrected the code above. Sorry 'bout that...
#9

[eluser]pistolPete[/eluser]
Use file_exists() instead of exists().
#10

[eluser]markanderson993[/eluser]
Strange, I added the code and the logs/unknown_mimes.log and attempt to upload non-mp3 files like pdfs but nothing shows up in the log :/

I appreciate all your help on this.




Theme © iAndrew 2016 - Forum software by © MyBB