i have try and try and i just cant get my image to upload. And i cant grab my image name when i try to echo it out :S.
can you see what im doing wrong.
here is my controller:
<?php
//ADMIN PAGE
if (! defined('BASEPATH')) exit('No direct script access');
class News extends CI_Controller {
//Write post when logged in as admin
function write()
{
//insert image
$config['upload_path'] = APPPATH .'/archive/img/news/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '9000';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
$this->upload->do_upload('newsImage');
$file_data = $this->upload->data();
$newsData = array(
'headline' => $this->input->post('headline'),
'description' => $this->input->post('description'),
'content' => $this->input->post('content'),
'creater' => $this->session->userdata('username'),
'ip' => $this->session->userdata('ip'),
'imgPath' => $file_data['file_name']
);
echo "<pre>";
//print_r( $this->upload->data());
//print_r($file_data);
//print_r($_FILES);
//print_r($this->input->post());
print_r($newsData);
echo "</pre>";
$this->load->model('admin/news_model');
$this->news_model->insertNews($newsData);
$data['main_content'] = 'admin/write_view';
$this->load->view('template', $data);
}
}
And my view file where i upload my image
<div id="inputStyle">
<?php
echo form_open_multipart('admin/news/write');
echo form_input('headline', 'overskrift');
echo form_upload('newsImage');
echo form_textarea('description', 'indhold');
echo form_textarea('content', 'content');
echo form_submit('create', 'Opret nyhed');
echo form_close();
?>
</div><!-- inputStyle -->