我試圖上傳一個使用codeigniter的圖像,不管是什麼 我總是收到「您沒有選擇要上傳的文件」錯誤。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>
誰能幫我解決這個問題呢?我感謝所有幫助:)
這是一個文件不是一個帖子'$圖像= $這個 - >輸入 - >後( 'userfile的');' – user4419336