EllisLab text mark
Advanced Search
1 of 2
1
   
Problem Uploading Mp3 and Video files
Posted: 28 March 2008 04:45 AM
Joined: 2008-03-22
10 posts

Hello experts i’m facing problem with uploading mp3 and video (3gp and mp4) files via upload class.
Here is my code

$config['upload_path''./uploads/mp3';
        
$config['allowed_types''mp3';
        
$config['max_size']    '2048'

The Error massage i get by this code

$error = array('error' => $this->upload->display_errors());
            
            
            
print_r($error); 

And the massage is

Array ( [error] =>

The filetype you are attempting to upload is not allowed.

How can i get rid of it ? And what file type will be for video ?? will it

$config['allowed_types''3gp|mp4'

Thanks in advance.

 
Posted: 28 March 2008 05:51 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-11
166 posts

For Error Messages:
Go to:system/language/english/upload_lang.php

And File-Type for Video Uploading depends upon, which you want to get supported by server+your application scope.
Video types: http://www.fileinfo.net/filetypes/video.
Visit the above URL.

 Signature 

http://www.nirbhab.com/  |  Follow Me On Twitter

 
Posted: 28 March 2008 09:23 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-03-22
10 posts

OK but what about the mp3 files ? I saw them listed on mime.php so why i cant upload mp3 via CodeIgniter ?

 
Posted: 28 March 2008 09:59 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-11
166 posts

you can upload any file of your choice, add the EXT of the file in the mime type, it won’t give any problem at all. I haven’t tried uploading mp3 file type. if you facing too much problem, let us know..we try to code and let you know the changes we have done or try to share our code.

 Signature 

http://www.nirbhab.com/  |  Follow Me On Twitter

 
Posted: 28 March 2008 10:26 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2008-03-22
10 posts

Dear here is my code for mp3 upload

<?php
class uploadmp3 extends controller    {

    
function uploadmp3()
        
{
        
        parent
::controller();
        
$this->load->helper('form');
        
$this->load->helper('url');
        
$this->load->database();
        
}

    
    
function index()
        
{
        
        $this
->load->view('add_mp3');
        
        
}
        
    
function do_upload()
        
{
        $config[
'upload_path''./uploads/mp3';
        
$config['allowed_types''mp3';
        
$config['max_size']    '2048';
        
        
        
$this->load->library('upload'$config);
    
        if ( ! 
$this->upload->do_upload())
        
{
            $error 
= array('error' => $this->upload->display_errors());
            
            
//$this->load->view('error', $error);
            
print_r($error);
        
}    
        
else
        
{
            $data 
= array('upload_data' => $this->upload->data());
        
        if(
$this->db->query($sql))    
            
$this->load->view('success');
    
        
}
        
    }



?> 

and here for video

?php
class uploadvideo extends controller    {

    
function uploadvideo()
        
{
        
        parent
::controller();
        
$this->load->helper('form');
        
$this->load->helper('url');
        
$this->load->database();
        
}

    
    
function index()
        
{
        
        $this
->load->view('add_video');
        
        
}
        
    
function do_upload()
        
{        
        $config[
'upload_path''./uploads/video';
        
$config['allowed_types''3gp|mp4';
        
$config['max_size']    '2048';

        
$this->load->library('upload'$config);
    
        if ( ! 
$this->upload->do_upload())
        
{
            $error 
= array('error' => $this->upload->display_errors());
            
            
$this->load->view('error'$error);
        
}    
        
else
        
{
            $data 
= array('upload_data' => $this->upload->data());
        
        if(
$this->db->query($sql))    
            
$this->load->view('success');
    
        
}
        
    }



?> 

Please help me to find out the solution.

 
Posted: 28 March 2008 10:33 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-11
166 posts

Code Seems ok to me, i hope the file you are uploading by ‘uploadmp3’ class is XYZ.mp3?
Please do consider the extension of uploading file…..

 Signature 

http://www.nirbhab.com/  |  Follow Me On Twitter

 
Posted: 28 March 2008 10:44 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2008-03-22
10 posts

Yes of course its mp3.

 
Posted: 17 April 2008 11:22 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2007-10-30
4 posts

hi there im stuck with the same problem with mp3’s…

Uploading works smooth with firefox. but not IE and Safari. Other than firefox i get…
“The filetype you are attempting to upload is not allowed”

This is in my mime.php

'mp3'    =>    array('audio/mpeg','audio/mpeg3','audio/mpg'), 

i also tried

'mp3'    =>    'audio/mpg'
 Signature 

http://www.coroflot.com/brownhand

 
Posted: 26 June 2008 03:10 AM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2008-06-05
333 posts

Guys ,i think this one can make it posible plz try it ,

‘mp3’  =>  array(‘audio/mpeg’,‘audio/mpeg3’,‘audio/mpg’,‘audio/x-mpeg’,‘audio/mp3’),
Hope it works.
.................JaMzEe

 Signature 

Zeeshan RasooL
Lahore - Pakistan
http://www.99Points.info


Facebook Wall Script Facebook Style Extract URL data with JQuery Ajax Rating System Script Who Am I

 
Posted: 15 February 2009 12:54 PM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-07
2 posts

I´ve had the same problem… I tried a series of possibilities until I discovered my firefox was setting the content-type to ‘application/force-download’ and my explorer was setting the type to ‘application/octet-stream’.

by setting my mime to this:

‘mp3’  =>  array(‘audio/mpeg’,‘audio/mpeg3’,‘audio/mpg’,‘audio/x-mpeg’,‘audio/mp3’,‘application/force-download’,‘application/octet-stream’),

I solved the problem in all browsers.

Hope this helps you all.

 
Posted: 30 April 2009 05:35 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2008-02-16
18 posts

I am having this problem as well. It is very wierd. bugzbrown, I tried your solution, but to no avail.
in my controller I have:

...
$config['upload_path'SERVER_PATH.'/assets/uploads/tmp';
$config['allowed_types''gif|jpg|jpeg|jpe|png|mp3';
$config['max_size']    '2048';
            
$this->load->library('upload'$config); 

And mime types:

...
'mp3'    =>    array('audio/mpeg','audio/mpeg3','audio/mpg','audio/x-mpeg','audio/mp3','application/force-download','application/octet-stream'),
'jpg'    =>    array('image/jpeg''image/pjpeg''application/octet-stream'),
... 

The only difference is I am using swfuploader. Never had this problem before (I’ve used swfupload in many projects). Using swfupload, I know all mimes need to have the application/octet-stream to work

anyway.
All images upload fine no problem.
When I upload an MP3 ( < 2mb of course because of the size limit) i get the error:

The filetype you are attempting to upload is not allowed

So, I am scratching me head on this one.

Edit:
Also just tried this combo:

'mp3'   =>      array('audio/mpeg''audio/x-mpeg''audio/mp3','audio/x-mp3','audio/mpeg3','audio/x-mpeg3','audio/mpg','audio/x-mpg','audio/x-mpegaudio''application/octet-stream'), 

Still did not work.

Another Edit:
I just checked the Mime-Type of the incoming file, and it is
application/octet-stream so now I am just stumped why code igniter says it is not allowed. (the extension is .mp3 of the file I’m uploading btw)

Here is all the info under the $_FILES[‘userfile’]:

$_FILES['userfile'{"name":"test.mp3","type":"application/octet-stream","tmp_name":"/tmp/phpkqLbnQ","error":0,"size":2012708} 

Also, I did this from a regular HTML upload form (without swfuploader) got the same thing. File type not allowed. :(

 
Posted: 01 May 2009 04:31 AM   [ # 11 ]   [ Rating: 0 ]
Joined: 2008-02-16
18 posts

Ok, well I figured it out. Hopefully this helps someone still…

In my config array, I had it like this:

..
$config['allowed_types''gif|jpg|jpeg|jpe|png|mp3';
$this->load->library('upload'$config); 

What you want to do is, put the mp3 in the front, before all the other file types, like so:

..
$config['allowed_types''mp3|gif|jpg|jpeg|jpe|png';
$this->load->library('upload'$config); 

Heres Why:
Here is the part of the function in the Upload.php Core Library that checks for allowed filtypes. I only pasted the important part (the first part)

function is_allowed_filetype()
{
    
    $image_types 
= array('gif''jpg''jpeg''png''jpe');
    foreach (
$this->allowed_types as $val)
    
{
        $mime 
$this->mimes_types(strtolower($val));

        
// Images get some additional checks
        
if (in_array($val$image_types))
        
{
            
if (getimagesize($this->file_temp) === FALSE)
            
{
                    
return FALSE;
            
}
        }
... 

Heres what happens. If you have your allowed type with the image file extension first
like

$config['allowed_types''gif|jpg|jpeg|jpe|png|mp3'

The for loop will check them in order. It will start with gif, then jpg, then jpeg, etc.

The first IF statement in the loop, checks to see if the allowed filetype is an image filetype (as there is a variable array containing image types above it $image_types)

well gif (the first in my allowed types) matches, so into the if statement it goes.

The next if statement, it checks for a valid image, by calling the function getimagesize(). Well, I uploaded an MP3, which is not an image, so getimagesize returns false… into the if statement.

return false. returning false ends the forloop right on the spot returning saying its an invalid filetype, and so it doesn’t continue on the rest of your allowed mime types to see of your MP3 is allowed or not.

if you upload an mp3, and an image format is listed first an your allowed_types config array, it will return Filetype not allowed as it will fail the test of the image types.


Now, if mp3 is listed first, and you upload an image, your ok, because the the first If statement will be skipped while checking the mp3 filetype, as the loop comes around again, it will check the image, getimagesize() wont return false, etc.

So it seems the best solution, is to always list image filetype LAST in your allowed_types config array.

Hope this helps.

 
Posted: 28 July 2009 07:27 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2006-12-20
401 posts

i had the same problem…didn’t recognize the filetype and give me this message

The filetype you are attempting to upload is not allowed

well, the problem wasn’t the mime types in mimes.php, it was that the server ( i guess ) added ‘\”’ or ‘“’ to the [‘type’] var, sonow i use this to clean the extra quotes.

$_FILES['user_file']['type'str_replace('\"' '' $_FILES['user_file']['type');

$_FILES['user_file']['type'str_replace('"' '' $_FILES['user_file']['type'); 

i know it’s not elegant….but it works

 Signature 

Don’t be so humble, you’re not that great ...

Practicing my english…don’t be a dick about it !!

 
Posted: 07 December 2009 07:10 PM   [ # 13 ]   [ Rating: 0 ]
Joined: 2008-06-10
21 posts

@~Chris~

Awesome man! This really droved me crazy! Thanks!

 
Posted: 22 June 2010 06:53 AM   [ # 14 ]   [ Rating: 0 ]
Joined: 2009-01-23
12 posts

Hy,

I know it`s kind of late to post a reply/solution for this problem but here is what I`ve found.

The problem is from the Upload.php Class in is_allowed_filetype() function because there is a line that says:

in_array($val$image_types)) 

than return false.

The problem is that $val is not our file extension so what I`ve done was some changes in this function. In fact, I`ve changed this function to this:

function is_allowed_filetype()
    
{
        
if (count($this->allowed_types) == OR ! is_array($this->allowed_types))
        
{
            $this
->set_error('upload_no_file_types');
            return 
FALSE;
        
}
                
        $image_types 
= array('gif''jpg''jpeg''png''jpe');
                
                if(!
in_array(strtolower(preg_replace('/\./'''$this->file_ext)), $this->allowed_types)){
                    
return FALSE;
                
}

        
foreach ($this->allowed_types as $val)
        
{
            $mime 
$this->mimes_types(strtolower($val));
                        
                        if(
is_array($mime) && (in_array($this->file_type$mime))){
                            
return TRUE;
                        
}elseif((is_string($mime)) && ($mime === $this->file_type)) {
                            
return TRUE;
                        
}
                        
                        
if((in_array(strtolower(preg_replace('/\./'''$this->file_ext)), $image_types)) && (getimagesize($this->file_temp)) == false){
                            
return FALSE;
                        
}
        }
        
        
return FALSE;
    

Now, if someone have some problems with this function, or if something is not correct, than please tell me. For me, this function works great.

In fact, for .mp3 file format which has the audio/mp3 file type I use the mime type

'mp3'    =>    array('audio/mpeg''audio/mpeg3''audio/mpg''audio/x-mpeg''audio/mp3'), 

So please feel free to use this function till something goes wrong. smile

 
Posted: 26 August 2010 05:19 AM   [ # 15 ]   [ Rating: 0 ]
Joined: 2009-02-17
12 posts
vitoco - 28 July 2009 11:27 PM

i had the same problem…didn’t recognize the filetype and give me this message

The filetype you are attempting to upload is not allowed

well, the problem wasn’t the mime types in mimes.php, it was that the server ( i guess ) added ‘\”’ or ‘“’ to the [‘type’] var, sonow i use this to clean the extra quotes.

$_FILES['user_file']['type'str_replace('\"' '' $_FILES['user_file']['type');

$_FILES['user_file']['type'str_replace('"' '' $_FILES['user_file']['type'); 

i know it’s not elegant….but it works

@vitoco

thank’s a lot

it works for me

 
1 of 2
1