Welcome Guest, Not a member yet? Register   Sign In
Strange problem with file upload
#1

Hello family. First I apologize if my english is not perfect, I translated automatically through google translate.
I have a strange problem. First I try to upload mp3 files using the codeigniter upload library. But it turns out that sometimes some files are sent while other files not. All the files I'm trying to send are of mp3 type and I do not think the problem comes from the size of the file. The error message is: The file type you are trying to send is not allowed. And Here is my controller:
PHP Code:
public function send_music(){
 
       $config = array(
 
'upload_path' => "./uploads/musiques/",
 
'allowed_types' => "mp3|ogg",
 
'max_size' => 20480,
 
'file_ext_tolower' => TRUE,
 
'encrypt_name' => TRUE,
 
'remove_spaces' => TRUE
 
);
 
$this->upload->initialize($config);
 if(
$this->upload->do_upload('mymusic')){
 
               echo $this->upload->data('file_name');
 }
 else{
 
               $error = array('error' => $this->upload->display_errors());
 
               foreach($error as  $key => $value){
 
               $this->alert->set('alert-danger'$key.' =>'.$value);
 
               }
 
               return $error;
 }
 
   
Simplicity is the ultimate sophistication
Reply
#2

(This post was last modified: 02-19-2018, 05:06 PM by php_rocs.)

@LEBOSSS,

What is the version of PHP and Codeigniter? Have you verified that the file types are listed in your mimes config file (it should be by default but check it anyway)? Are you sure that the files are type mp3 and not mp4 or some other file type? Is your upload file directory set correctly to allow files to be uploaded to it (777)?
Reply
#3

(This post was last modified: 02-19-2018, 05:25 PM by LEBOSSS.)

It is the latest version. And i'm just trying to upload mp3 files! And I think my upload directory is correctly set. Because sometimes some files is uploaded and other files not. And when i try the file helper function get_mime_by_extension, it's always give me audio/mp3
Simplicity is the ultimate sophistication
Reply
#4

(02-19-2018, 04:37 PM)LEBOSSS Wrote: Hello family. First I apologize if my english is not perfect, I translated automatically through google translate.
I have a strange problem. First I try to upload mp3 files using the codeigniter upload library. But it turns out that sometimes some files are sent while other files not. All the files I'm trying to send are of mp3 type and I do not think the problem comes from the size of the file. The error message is: The file type you are trying to send is not allowed. And Here is my controller:
PHP Code:
public function send_music(){
 
       $config = array(
 
'upload_path' => "./uploads/musiques/",
 
'allowed_types' => "mp3|ogg",
 
'max_size' => 20480,
 
'file_ext_tolower' => TRUE,
 
'encrypt_name' => TRUE,
 
'remove_spaces' => TRUE
 
);
 
$this->upload->initialize($config);
 if(
$this->upload->do_upload('mymusic')){
 
               echo $this->upload->data('file_name');
 }
 else{
 
               $error = array('error' => $this->upload->display_errors());
 
               foreach($error as  $key => $value){
 
               $this->alert->set('alert-danger'$key.' =>'.$value);
 
               }
 
               return $error;
 }
 
   

Maybe try changing this:


PHP Code:
'upload_path' => "./uploads/musiques/"


to this:


PHP Code:
'upload_path' => "uploads/musiques/"


and then load the library, even if you autoload it you might sometimes find some troubles with it. Just before initializing the config file. Just put this:

PHP Code:
$this->load->library('upload'$config);

$this->upload->initialize($config); 

and the third advise, where are you getting the "mymusic" input from? You have not declare it, in the official docs it says that if you have your own input name you need to declare it before the $this->upload->do_upload(); here:


PHP Code:
$file_name 'mymusic';

if(
$this->upload->do_upload($file_name)){
// your code
} else {
// more of you code


I hope I could make myself clear.
I do Front-End development most of the time 
Reply
#5

Thank you @kirasiris, i made all of yur suggested modifications but no way. It's not working.
I want to ask one question: Is it possible that a file has mp3 extension but is not mp3 file?
Simplicity is the ultimate sophistication
Reply
#6

(02-19-2018, 06:47 PM)LEBOSSS Wrote: Thank you @kirasiris, i made all of yur suggested modifications but no way. It's not working.
I want to ask one question: Is it possible that a file has mp3 extension but is not mp3 file?

This is what your code should look if you want it to send it to a database and into a folder.

PHP Code:
            // Upload mp3/Ogg File
            
$config['upload_path'] = 'uploads/musiques/';
            
$config['allowed_types'] = 'mp3|ogg';
            
$config['encrypt_name'] = TRUE;
            
$config['file_ext_tolower'] = 'TRUE';
            
$config['remove_spaces'] = 'TRUE';
            
$this->load->library('upload'$config);
            
$this->upload->initialize($config);
                    
            
            
$file_name 'mymusic';
            
            if(!
$this->upload->do_upload($file_name)){
                
var_dump($this->upload->display_errors());
                
$file_name 'uploads/musiques/nofileselected.jpg';
            } else {
                
$post_image  $this->upload->data('file_name');
            }
            
            
// If you want to send it to your database as well, you have to put it like this:
 
           $data = array(
                
'slug'            => $slug,
                
'title'            => $this->input->post('title'),
                
'mymusic'    => $post_image,
 
           ); 

try and see if it works, and to respond your second question about uploading a file that looks like an mp3 file but its not, I will highly recommend you to convert any file into mp3 before uploading just to  make sure you dont mess with uploading class; or if you have any idea of what the real extension of the file is, then added it to the allowed_types parameter and see if it works.
I do Front-End development most of the time 
Reply
#7

(02-19-2018, 07:13 PM)kirasiris Wrote:
(02-19-2018, 06:47 PM)LEBOSSS Wrote: Thank you @kirasiris, i made all of yur suggested modifications but no way. It's not working.
I want to ask one question: Is it possible that a file has mp3 extension but is not mp3 file?

This is what your code should look if you want it to send it to a database and into a folder.

PHP Code:
// Upload mp3/Ogg File
 
$config['upload_path'] = 'uploads/musiques/';
 
$config['allowed_types'] = 'mp3|ogg';
 
$config['encrypt_name'] = TRUE;
 
$config['file_ext_tolower'] = 'TRUE';
 
$config['remove_spaces'] = 'TRUE';
 
$this->load->library('upload'$config);
 
$this->upload->initialize($config);
 
 
 
$file_name 'mymusic';
 
 if(!
$this->upload->do_upload($file_name)){
 
var_dump($this->upload->display_errors());
 
$file_name 'uploads/musiques/nofileselected.jpg';
 } else {
 
$post_image  $this->upload->data('file_name');
 }
 
 
// If you want to send it to your database as well, you have to put it like this:
 
           $data = array(
 
'slug' => $slug,
 
'title' => $this->input->post('title'),
 
'mymusic' => $post_image,
 
           ); 

try and see if it works, and to respond your second question about uploading a file that looks like an mp3 file but its not, I will highly recommend you to convert any file into mp3 before uploading just to  make sure you dont mess with uploading class; or if you have any idea of what the real extension of the file is, then added it to the allowed_types parameter and see if it works.

My code exactly look like yours except the part of sending into a database but it still not working.

Just to be sure that you understand my problem, I have to remind you that the upload works, but it does not work for all mp3 files. Some mp3 files are correctly uploaded others not. Why? I have no idea. May be it's about the file i'm trying to upload.
Simplicity is the ultimate sophistication
Reply
#8

(02-19-2018, 07:34 PM)LEBOSSS Wrote:
(02-19-2018, 07:13 PM)kirasiris Wrote:
(02-19-2018, 06:47 PM)LEBOSSS Wrote: Thank you @kirasiris, i made all of yur suggested modifications but no way. It's not working.
I want to ask one question: Is it possible that a file has mp3 extension but is not mp3 file?

This is what your code should look if you want it to send it to a database and into a folder.

PHP Code:
// Upload mp3/Ogg File
 
$config['upload_path'] = 'uploads/musiques/';
 
$config['allowed_types'] = 'mp3|ogg';
 
$config['encrypt_name'] = TRUE;
 
$config['file_ext_tolower'] = 'TRUE';
 
$config['remove_spaces'] = 'TRUE';
 
$this->load->library('upload'$config);
 
$this->upload->initialize($config);
 
 
 
$file_name 'mymusic';
 
 if(!
$this->upload->do_upload($file_name)){
 
var_dump($this->upload->display_errors());
 
$file_name 'uploads/musiques/nofileselected.jpg';
 } else {
 
$post_image  $this->upload->data('file_name');
 }
 
 
// If you want to send it to your database as well, you have to put it like this:
 
           $data = array(
 
'slug' => $slug,
 
'title' => $this->input->post('title'),
 
'mymusic' => $post_image,
 
           ); 

try and see if it works, and to respond your second question about uploading a file that looks like an mp3 file but its not, I will highly recommend you to convert any file into mp3 before uploading just to  make sure you dont mess with uploading class; or if you have any idea of what the real extension of the file is, then added it to the allowed_types parameter and see if it works.

My code exactly look like yours except the part of sending into a database but it still not working.

Just to be sure that you understand my problem, I have to remind you that the upload works, but it does not work for all mp3 files. Some mp3 files are correctly uploaded others not. Why? I have no idea. May be it's about the file i'm trying to upload.

http://php.net/manual/en/function.finfo-file.php <- use this to check the mime type
Reply
#9

It's resolved! How? Just the ultimate solution i.e upload again the system folder! and now, everything going right.
Thanks to @php_rocs and @kirasiris!
Simplicity is the ultimate sophistication
Reply




Theme © iAndrew 2016 - Forum software by © MyBB