我尝试使用Postman上传文件,但收到错误消息:You did not select a file to upload.
我不知道是什么原因,但也试图找到方法。
public function upload_post()
{
$this->load->helper(array('form', 'url'));
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload',$config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
$this->set_response($data, REST_Controller::HTTP_CREATED);
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->response($error, REST_Controller::HTTP_BAD_REQUEST);
}
}
看看html:
<?php echo $error;?>
<?php echo form_open_multipart('api/example/upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
$this->upload->do_upload('file')
和密钥file
邮递员。答案 0 :(得分:0)
enctype='multipart/form-data'