5
In my view there’s this field:
<form class="form-horizontal"method="post" action="<?=base_url('index.php/home/cadastro')?>" enctype="multipart/form-data">
<input id="img" name="img" class="input-file" type="file">
In my controller I have the following:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MY_Controller {
public function index()
{
$this->load->view('v_home');
}
public function cadastro()
{
$titulo = $this->input->post('titulo');
$texto = $this->input->post('texto');
$link = $this->input->post('link');
$nome_link = $this->input->post('nome_link');
$img = $this->input->post('img');
$dados = array(
'titulo' => $titulo,
'texto' => $texto,
'link' => $link,
'nome_link' => $nome_link,
'img' => $img,
'data' => date("Y-m-d H:i:s")
);
//print_r($dados);
$this->load->model('noticia_model');
$casdatro = $this->noticia_model->cadastrar_noticia($dados);
if($casdatro){
$this->session->set_flashdata('mensagem', 'Cadastro realizado com sucesso');
}else{
$this->session->set_flashdata('mensagem', 'Erro no cadastro');
}
//redirect(base_url('cadastrar_view'));
}
public function cadastrar()
{
$this->load->view('cadastrar_view');
}
}
Only that $img = $this->input->post('img');
is not getting the edge
Someone helps?
tries using $_FILE['img']
– Marcelo Diniz
Possible duplicate of Upload images to Codeigniter
– user26552
NO CI, you will not be able to upload this way, neither with file, nor with post, you will only be able to do it using his upload library, today they have also posted a question about it, see if it helps you: http://answall.com/questions/157944/erro-voc%C3%AA-n%C3%A3o-selected-o-file-to-do-upload-codeigniter
– Sr. André Baill
https://www.codeigniter.com/userguide3/libraries/file_uploading.html
– user26552