Good,
First I wanted to say that I do not understand anything, but nothing of CodeIgniter, I never worked, I had not even heard of it. But the site is so done and I was asked to add an upload of images. And so I did, but evil. Here is the code for the " form ":
<?php echo form_open_multipart('admin/add_images_construcao');?>
<div class="form-group">
<div class="col-md-12" style="padding: 0px; margin: 0px;">
<label>Descrição</label>
<textarea name="texto" id="texto" class="col-md-12 "></textarea>
</div>
<div class="col-md-12" style="padding: 0px;">
<input type="file" name="userfile" onchange="readURL(this);" size="20" />
<input type="submit" value="Upload" class="btn btn-default"/>
</div>
</div>
</form>
This was even easy. Now comes the code that I've been working on, drawing a little bit from here and there.
public function add_images_construcao() {
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$this->load->helper('url');
$this->load->database();
$id = $this->input->post('id');
$texto = $this->input->post('texto');
$nome_pasta = $id;
$dir = './assets/img/construcao/'.$nome_pasta;
if (file_exists($dir)) {
echo '';
} else {
mkdir('./assets/img/construcao/' . $nome_pasta, 0777, TRUE);
}
$config['upload_path'] = './assets/img/construcao/'.$nome_pasta;
$config['allowed_types'] = '*';
$config['max_size'] = '10000';
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
$error = array('error' =>$this->upload->display_error());
$this->load->view('admin/home', $error);
}else{
$file_data = $this->upload->data();
$data['img'] = base_url().'/assets/img/construcao/'.$file_data['file_name'];
$data = array (
"id" => $id,
"texto" => $texto,
"ficheiro" => $file_data['file_name']
);
$this->db->insert('construcao', $data);
$this->load->view('admin/header');
$this->load->view('admin/navigation', $data);
$this->load->view('admin/home', array('error'=>''));
$this->load->view('admin/footer');
}
redirect('admin/home', 'refresh');
}
else
{
redirect('home', 'refresh');
}
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('user','',TRUE);
$data = array(
'titulo' => $this->input->post('titulo'),
'texto' => $this->input->post('texto'),
'data' => date('d-M-y')
);
$this->db->insert('noticias', $data);
redirect('admin/home', 'refresh');
}
And this is what I did after 1 month .. Can anyone help me?