Загрузите файл изображения и сохраните MYSQL Codeigniter

Я пытаюсь загрузить изображение на свой сайт через форму, и у меня проблемы с формой, и я действительно не знаю, куда идти:

<?php echo form_open_multipart('login/save');?>

<table>

<tr>
<td>Title</td>
<td><input type="text" name="title"></input></td>
</tr>
<tr>
<td><input type="file" name="userfile" size="20" /> </td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></input></td>
</tr>
</table>
<?php
echo form_close();
?>

Мой контроллер:

<?php
class Login extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
}
public function index(){
$this->load->model('mlogin');
$this->load->view('login/a', array('error' => ' ' ));
}
public function save(){

$this->load->model("Mlogin");
if($this->input->post("submit")){

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
if ( function_exists( 'date_default_timezone_set' ) ) date_default_timezone_set('Asia/Ho_Chi_Minh');
$date = date("His_dmY_");
$config['file_name']  = $date;
$config['max_width']  = '1024';
$config['max_height']  = '768';
$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

$this->load->view('login/a', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());

}
}
//redirect("login/a");$this->Mlogin->add();
echo "Success!";
}}
?>

Моя модель:

<?php
class Mlogin extends CI_Model{
public function __construct(){
parent::__construct();
$this->load->database();}

public function add(){
$title = $this->input->post("title");
$data = array(
"title"=>$title,
"image"=>$file_name
);
$this->db->insert("abc",$data);
}//end of simpan
}
?>

Должен ли я делать что-то другое? Не совсем уверен, что происходит не так.
Ошибка:

Обнаружена ошибка PHP

Серьезность: Уведомление

Сообщение: неопределенная переменная: имя_файла

Имя файла: models / mlogin.php

Номер строки: 23

Ошибка базы данных Произошла

Номер ошибки: 1054

Чемпионский титул чемпиона Инконну Данс

ВСТАВИТЬ В abc (title, image) VALUES (‘342342’, NULL)

Имя файла: C: \ wamp \ www \ system \ database \ DB_driver.php

Номер строки: 330

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector