Welcome Guest, Not a member yet? Register   Sign In
Uploading MP3
#1

[eluser]rijobo[/eluser]
Hello,

I'm trying to build a form in which you can upload mp3 files. When I use the code below, it does put some data in the database, but it doesn't upload the file to the server and it also doesn't put the path in the database. What do I do wrong?

Controller:

Code:
function create(){
        if ($this->input->post('titel')){
            $this-> mmuziek-> addMuziek();
            $this-> session-> set_flashdata('message','Nieuwe muziek aangemaakt');
            redirect('ledenhoek/muziek/index','refresh');
        }else{
            $data['title'] = "Nieuwe muziek aanmaken";
            $data['main'] = 'admin_muziek_create';
            $this-> load-> vars($data);
            $this-> load-> view('dashboard', array('error' => '' ));
        }
    }

Model:

Code:
function addMuziek(){
        $data = array(
            'artiest' => $_POST['artiest'],
            'titel' => $_POST['titel'],
            'partij' => $_POST['partij'],
            'status' => $_POST['status']
        );
        $config['upload_path'] = './muziek/';
        $config['allowed_types'] = 'mp3';
        $config['max_size'] = '200000000';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $this-> load-> library('upload', $config);
        
        if(!$this-> upload-> do_upload()){
            $error = array('error' => $this-> upload-> display_errors());
            $this->load->view('admin_muziek_create', $error);
        }
        $muziek = $this-> upload-> data();
        if ($muziek['file_name']){
            $data['muziek'] = "/muziek/".$muziek['file_name'];
        }
        $this-> db-> insert('muziek', $data);
    }

View:

Code:
<h1>&lt;?php echo $title;?&gt;</h1>
&lt;?php
echo $error;
echo form_open_multipart('ledenhoek/muziek/create');

echo"<p><label for='artiest'>Artiest</label><br/>";
$data = array('name'=>'artiest','id'=>'artiest','size'=>25);
echo form_input($data) ."</p>";
echo"<p><label for='titel'>Titel</label><br/>";
$data = array('name'=>'titel','id'=>'titel','size'=>25);
echo form_input($data) ."</p>";
echo "<p><label for='partij'>Stempartij</label><br/>";
$options = array('bas' => 'bas', 'tenor' => 'tenor', 'eerste alt' => 'eerste alt', 'tweede alt' => 'tweede alt', 'sopraan' => 'sopraan', 'mezzosopraan' => 'mezzosopraan');
echo form_dropdown('partij',$options)."</p>";

echo "<p><label for='muziek'>Muziek</label><br/>";
$data = array('name'=>'muziek','id'=>'muziek');
echo form_upload($data)."</p>";
echo "<p><label for='status'>Status</label><br/>";
$options = array('actief' => 'actief', 'non-actief' => 'non-actief');
echo form_dropdown('status',$options) ."</p>";
echo form_submit('submit','Nieuwe muziek aanmaken');
echo form_close();
?&gt;
#2

[eluser]slowgary[/eluser]
This is just a guess, but are you sure this path is correct?
Code:
$config['upload_path'] = './muziek/';
Try adding the full path from server root, like '/var/www/music/'. You may also want to double check that the directory is_writable();
#3

[eluser]rijobo[/eluser]
Thanks for your help!

I'm using this path also for my images and that works fine. I'm using a wamp server local on my pc, so standard my directory should be writable I believe.
#4

[eluser]rijobo[/eluser]
Can someone please help me? I need to show this in 45 minutes and I can't find what I do wrong.
#5

[eluser]danmontgomery[/eluser]
do_upload() by default is looking for a field named 'userfile'. If this isn't the name of your upload field name (looks like 'muziek' in your case), you need to pass that value to do_upload().

From the user guide,

Quote:$this->upload->do_upload()

Performs the upload based on the preferences you've set. Note: By default the upload routine expects the file to come from a form field called userfile, and the form must be a "multipart type:

Code:
&lt;form method="post" action="some_action" enctype="multipart/form-data" /&gt;
If you would like to set your own field name simply pass its value to the do_upload function:

Code:
$field_name = "some_field_name";
$this->upload->do_upload($field_name)
#6

[eluser]rijobo[/eluser]
Done that, but still it doesn't fill my database with the path and the upload isn't taking place.




Theme © iAndrew 2016 - Forum software by © MyBB