[eluser]Cryorus[/eluser]
Hi everyone. Well, im a newbie learning this thing, pretty cool indeed. The site:
http://cryorus.ignavus.org/gedn/
In my admin panel, im trying to add news to the database with an image, submitting the info to my database. Submitting it was perfect till i added the file upload class, it uploads perfectly and i can still insert the info to the database, everything but the 'img' field. I did some debug and $this->input->post('img'), is empty. Now im insering to the database: "/resources/images/"
Im using dwoo for templates, so im not using any php code in my view files.
Here is my code.
Controller:
Code:
function add() {
$config = array(
array(
'field' => 'title',
'label' => 'Título',
'rules' => 'trim|required|min_length[5]|max_length[50]'
),
array(
'field' => 'img',
'label' => 'Imagen',
'rules' => 'trim'
),
array(
'field' => 'intro',
'label' => 'Introducción',
'rules' => 'trim|required'
),
array(
'field' => 'content',
'label' => 'Contenido',
'rules' => 'trim'
)
);
$up_config = array(
'upload_path' => './resources/images',
'allowed_types' => 'gif|jpg|png'
);
$this->load->library('upload', $up_config);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() && $this->upload->do_upload('img')) {
$data = array(
'title' => $this->input->post('title'),
'img' => '/resources/images/' . $this->input->post('img'),
'intro' => $this->input->post('intro'),
'content' => $this->input->post('content')
);
$ext = strstr($this->input->post('img'), '.');
$data['img_thumb'] = substr($data['img'], 0, -strlen($ext)) . '_thumb' . $ext; //done!
$this->_thumbnailer($this->input->post('img'));
$this->db->insert('news', $this->db->escape($data));
redirect('/admin/news/');
}
else {
$up_errors = $this->upload->display_errors('<h2 class="header error">', '</h2>');
$errors = validation_errors();
$this->dwootemplate->assign('errors', $errors);
$this->dwootemplate->assign('up_errors', $up_errors);
$this->dwootemplate->display('admin_news_add.tpl');
}
}
View:
Code:
<div id="news">
<h2 class="header center">Noticias</h2>
<form class="default addnew" action="/gedn/admin_news/add/" method="post" enctype="multipart/form-data">
{if $errors!=""}{$errors}{/if}
{if $up_errors!=""}{$up_errors}{/if}
{if $db_errors}<h2 class="header error">{$db_errors}</h2>{/if}
<p>
<label>Título:</label><input class="text_input" type="text" name="title" value="" size="90%" />
<br/>
<label>Imagen:</label><input class="text_input" type="file" name="img" size="50%" />
<br/>
<label>Introducción:</label><textarea name="intro" rows="6" cols="87" size="100%" ></textarea>
<br/>
<label>Contenido:</label><textarea name="content" rows="10" cols="87" size="100%" ></textarea>
<br/>
<input class="submit_input" type="submit" value="Entrar" />
</p>
</form>
</div>
Im pretty sure we dont need to know any of the other code.
Thanks in advance.
Edit: if in wrong section, please move, sorry.