【发布时间】:2016-01-13 07:47:41
【问题描述】:
我正在尝试使用 codeigniter 上传图片,无论如何 我不断收到“您没有选择要上传的文件”错误。
这是我的控制器:
<?php
class Post extends CI_Controller {
function __construct(){
parent::__construct();
}
function index(){
$this->load->view('upload_form', array('error' => ''));
}
function upload(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '1024';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
echo json_encode($error);
}
else
{
$file_data = array('upload_data' => $this->upload->data());
$data['img'] = base_url().'/images/'.$file_data['file_name'];
echo json_encode($data);
}
}
}
?>
这是我的观点:
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE-9"/>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data" >
Select File To Upload:<br />
<input type="file" name="userfile" />
<br /><br />
<input type="submit" name="submit" value="Upload" class="btn btn-success" />
</form>
</body>
</html>
谁能帮我解决这个问题?感谢您的帮助:)
【问题讨论】:
标签: php codeigniter