Welcome Guest, Not a member yet? Register   Sign In
Audio uploader only working on SOME computers
#1

[eluser]markanderson993[/eluser]
I come to you with a very perplexing question that has caused me to have lost half my hair. Basically, I have an audio uploading script that only works on a few machines, and most others not. I believe the root of the problem lays in the mime types but the other me says it is a result of bad programming in my MVC.

Controller
Code:
if (isset($_POST['upload_audio']))
        {
            $rules['audio_title'] = "required";
            $rules['audio_group_id'] = "required";
            
            $fields['audio_title'] = 'audio title';
            $fields['audio_group_name'] = 'audio album';
            
            $this->validation->set_rules($rules);
            $this->validation->set_fields($fields);
            
            if(!$this->validation->run() || $_FILES['userfile']['error'] == 4)
            {
                if($_FILES['userfile']['error'] == 4)
                {
                    $this->validation->error_string .= $this->validation->_error_prefix.'The Audio selection field is required.'.$this->validation->_error_suffix;
                }    
            } else { // Everything is ok so far
                # Set uploading variables
                $config['upload_path'] = 'serve/'.$upload_folder.'/';
                $config['encrypt_name'] = FALSE;
                $config['allowed_types'] = 'mp3';
                $config['max_size'] = '60000';
                
                if (!$this->audio_model->is_audio($_FILES['userfile']['tmp_name'],'size'))
                {
                    $this->validation->error_string .= $this->validation->_error_prefix.'The audio selection cannot be any longer than 20 minutes.'.$this->validation->_error_suffix;
                } else {
                
                    $this->load->library('upload',$config);
                    
                    if (!$this->upload->do_upload())
                    {
                        $data = array('error' => $this->upload->display_errors());
                    } else {
                        # Run the next stage of validation
                        $upload_data = $this->upload->data();
                        foreach( $upload_data as $item => $value ) { $filedata[$item] = $value; }
                        
                        $audio_index_id = $this->audio_model->create_audio_index_id();
                        
                        $data['success'] = 'Audio file was successfully uploaded';
                        
                        # Add the audio_title and audio_desc to the upload_data array
                        $upload_data['audio_title'] = strip_tags(trim(htmlentities($this->input->post('audio_title'))));
                        $upload_data['audio_desc'] = strip_tags(trim(htmlentities($this->input->post('audio_desc'))));
                        
                        $this->audio_model->db_insert_audio($id,$upload_folder,$audio_index_id,$upload_data,$this->input->post('audio_group_id'));
                    }    
                }
            }

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

And finally, here is my model

Code:
function db_insert_audio($id,$upload_folder,$audio_index_id,$upload_data,$audio_group_id)
    {
        # Get array of extra audio info (Warning,Errors,Fizesize,Playtime,Audio Frequency,Tags)
        $audio_info = $this->_capture_audio_data($upload_folder,$upload_data['raw_name'].'.mp3');
        
        # Main Settings
        $file_ext = '.mp3';
        $dir = $_SERVER['DOCUMENT_ROOT'].'/serve/'.$this->user_info_model->get_upload_folder($id).'/';

        # Create a subfolder
        $subfolder = $this->functions->randomise(false,20);
        mkdir($dir.$subfolder);
        
        # Configure rename settings
        $audio_title = trim(strip_tags(htmlentities($upload_data['audio_title'])));
        $old_name = $upload_data['orig_name'];
        $new_name = $audio_title.$file_ext;
        
        rename($dir.$old_name, $dir.$subfolder.'/'.$new_name);
        
        # Define variables
        $date_added = now();
        $orig_ext = $upload_data['file_ext'];
        $orig_name = $upload_data['orig_name'];
        $file_name = $upload_data['audio_title'].$file_ext;
        $audio_desc = trim(strip_tags(htmlentities($upload_data['audio_desc'])));
        $filesize = $audio_info['filesize'];
        $playtime_seconds = $audio_info['playtime_seconds'];
        $playtime_string = $audio_info['playtime_string'];
        $audiofrequency = $audio_info['audiofrequency'];
        
        # Insert audio info
        $audio_info_array = array(
            'file_name' => $file_name,
            'subfolder' => $subfolder,
            'date_added' => $date_added,
            'orig_name' => $orig_name,
            'orig_ext' => $orig_ext,
            'file_ext' => $file_ext,
            'filesize' => $filesize,
            'playtime_seconds' => $playtime_seconds,
            'playtime_string' => $playtime_string,
            'audiofrequency' => $audiofrequency,
            'audio_title' => $audio_title,
            'audio_desc' => $audio_desc
        );
        
        # Insert data into audio_info table
        $this->db->insert('audio_info',$audio_info_array);
        
        $audio_id = $this->db->insert_id();
        
        # Insert audio id into audio_index
        $this->db->where('audio_index_id',$audio_index_id);
        $this->db->update('audio_index',array('audio_id' => $audio_id,'audio_group_id' => $audio_group_id,'date_added' => $date_added));
        
        # Insert audio id into audio_dir
        $this->db->insert('audio_dir',array('id' => $id,'audio_id' => $audio_id));
        
        # Increment user_upload_counter
#2

[eluser]markanderson993[/eluser]
This issue has become urgent at my website and needs to be resolved quickly. Due to the fact that I hate to push you, the cool dudes at Codeigniter around, I decided the first one who can quick the script to properly work should get $25 dollars on Paypal.

If you would like to be discreet PM me.
#3

[eluser]TheFuzzy0ne[/eluser]
Exactly what's not working? I see code, you've told us there's a problem, but you've not described any symptoms.
#4

[eluser]markanderson993[/eluser]
My site users aren't exactly telling me anything but that the script is throwing them an error saying
Quote:"File type not supported"
or a message conveying that idea. Which leads me to believe the error lies in the mime types. However I keep adding more and more and it never works on all computers.

The weird thing is I can upload audio on my computer, but somebody in Ohio can't. So confused! :/
#5

[eluser]TheFuzzy0ne[/eluser]
I think this line doesn't do your code any justice:
Code:
$this->validation->error_string .= $this->validation->_error_prefix.'The audio selection cannot be any longer than 20 minutes.'.$this->validation->_error_suffix;

It's been added after the validation has run, and it's a bit hacky. This test should be a validation callback. Simply add a method to your controller that passes the data to the model, and returns TRUE or false depending on the outcome.
#6

[eluser]markanderson993[/eluser]
Good catch Fuzzy, I'll definitely fix that. However I have a feeling that is not the the end-all fix :/
#7

[eluser]TheFuzzy0ne[/eluser]
No, it's not. I need to know the exact error message, word for word. Also, is this hosted on a third party server, or do you have full control over the server?
#8

[eluser]markanderson993[/eluser]
I can't recite for you the exact error message only that it was the common "Please upload the correct file type" error message CodeIgniter gives to someone who is uploading for instance a .gif into a script programmed to only accept a .jpeg file.

Example: $config['allowed_types'] = '.gif';
#9

[eluser]markanderson993[/eluser]
Now I'm getting from someone this

Quote:"i don't get an error message. the page just refreshes and all the fields go blank again."
#10

[eluser]markanderson993[/eluser]
I appreciate all your help on this so far Smile




Theme © iAndrew 2016 - Forum software by © MyBB