Welcome Guest, Not a member yet? Register   Sign In
Strange problem with file upload
#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


Messages In This Thread
Strange problem with file upload - by LEBOSSS - 02-19-2018, 04:37 PM
RE: Strange problem with file upload - by LEBOSSS - 02-19-2018, 05:15 PM
RE: Strange problem with file upload - by kirasiris - 02-19-2018, 06:23 PM
RE: Strange problem with file upload - by LEBOSSS - 02-19-2018, 06:47 PM
RE: Strange problem with file upload - by LEBOSSS - 02-19-2018, 07:34 PM
RE: Strange problem with file upload - by LEBOSSS - 02-20-2018, 07:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB