загрузчик изображений не работает в CI

Это моя страница просмотра

<?php echo form_open_multipart('admin/item/uploadImage'); ?>
<input type="file" name="file" id="file" />
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"');?>

и это моя страница контроллера:

class item extends Admin_Controller
{public function __construct ()
{
parent::__construct();
$this->load->model('item_m');
}

public function index ()
{
// Fetch all items
$this->data['items'] = $this->item_m->get();
// Load view
$this->data['subview'] = 'admin/item/index';
$this->load->view('admin/_layout_main', $this->data);}function uploadImage()

{

$config['upload_path']   =   "uploads/";

$config['allowed_types'] =   "gif|jpg|jpeg|png";

$config['max_size']      =   "5000";

$config['max_width']     =   "1907";

$config['max_height']    =   "1280";

$this->upload->initialize($config);
$this->load->library('upload',$config);

if(!$this->upload->do_upload($_POST['file']))

{

echo $this->upload->display_errors();

}

else

{

$finfo=$this->upload->data();

$data['uploadInfo'] = $finfo;

$data['thumbnail_name'] = $finfo['raw_name']. '_thumb' .$finfo['file_ext'];

//  $this->load->view('upload_success',$data);

// You can view content of the $finfo with the code block below

/*echo '<pre>';

print_r($finfo);

echo '</pre>';*/

}

//  $this->load->view('upload_success',$data);

// You can view content of the $finfo with the code block below

/*echo '<pre>';

print_r($finfo);

echo '</pre>';*/}}

я получаю ошибку, как это

A PHP Error was encountered
Severity: Notice
Message: Undefined index: file
Filename: admin/item.php
Line Number: 47
You did not select a file to upload.

помогите пожалуйста данные файла не переходят на страницу контроллера? я попытался вызвать doupload изображение из другой функции, но это не работает также.

1

Решение

Проблема с этим утверждением:

if(!$this->upload->do_upload($_POST['file']))

Здесь вы должны указать только имя параметра, например:

if(!$this->upload->do_upload('file'))
1

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

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

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