I can't upload mp3 files using Codeigniter

Posted by Drew on Stack Overflow See other posts from Stack Overflow or by Drew
Published on 2010-05-12T08:21:54Z Indexed on 2010/05/12 11:04 UTC
Read the original article Hit count: 275

Filed under:
|

There are lots of suggested fixes for this but none of them work for me. I have tried making the upload class (using the following methods: http://codeigniter.com/forums/viewthread/148605/ and http://codeigniter.com/forums/viewthread/125441/). When i try to upload an mp3 i get the error message "The filetype you are attempting to upload is not allowed". Below is my code for my model and my form (i've got a very skinny controller). If someone could help me out with this I would be eternally grateful.

--Model--

function do_upload()
{

        $soundfig['upload_path'] = './uploads/nav';
        $soundfig['allowed_types'] = 'mp3';

        $this->load->library('upload', $soundfig);

        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

            return $error;
        }   
        else
        {

            /* $data = $this->upload->data('userfile'); */
            $sound = $this->upload->data();
            /* $full_path = 'uploads/nav/' . $data['file_name']; */
            $sound_path = 'uploads/nav/' . $sound['file_name'];

            if($this->input->post('active') == '1'){
                $active = '1';
            }else{
                $active = '0';
            }

            $spam = array(
                /* 'image_url' => $full_path, */
                'sound' => $sound_path,
                'active' => $active,
                'url' => $this->input->post('url')
            );

            $id = $this->input->post('id');

            $this->db->where('id', $id);
            $this->db->update('NavItemData', $spam);

            return true;

    }
}

--View - Form--

<?php echo form_open_multipart('upload/do_upload');?>
<?php if(isset($buttons)) : foreach($buttons as $row) : ?>
<h2><?php echo $row->name; ?></h2>
<!-- <input type="file" name="userfile" size="20" /><br /> -->
<input type="file" name="userfile" size="20" />
<input type="hidden" name="oldfile" value="<?php echo $row->image_url; ?>" />
<input type="hidden" name="id" value="<?php echo $row->id; ?>" />

<br /><br />
<label>Url: </label><input type="text" name="url" value="<?php echo $row->url; ?>" /><br />
<input type="checkbox" name="active" value="1" <?php if($row->active == '1') { echo 'checked'; } ?> /><br /><br />
<input type="submit" value="submit" />

</form>

<?php endforeach; ?>
<?php endif; ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about codeigniter