我正在尝试使用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>
任何人都可以帮我解决这个问题吗?我感谢任何帮助:)
答案 0 :(得分:0)
您提交表单的功能,根据代码索引功能加载表单,您在同一页面上提交而不是上传功能
答案 1 :(得分:0)