[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><?php echo $title;?></h1>
<?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();
?>