我正在尝试使用codeigniter在我的API中实现一个简单的图像上传函数。
function addpicture_post()
{
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload() )
{
print_r($this->upload->display_errors('', ''));
print_r($this->upload->data());
$info = 'not working';
$this->response($info);
}
}
}
当我使用apigee(https://apigee.com/console/others)进行尝试时,如果我没有设置任何参数,我会看到以下消息:
HTTP/1.1 200正常状态:200日期:2013年12月12日星期四15:30:16 GMT内容长度:367保持活动:超时=15,最大=100内容类型:应用程序/json X-Powered-By:PHP/可扩展性5.3.5-1ubuntu7.11服务器:Apache/2.2.17(Ubuntu)
您没有选择要上载的文件。
到目前为止一切都很好。但是当我尝试上传一个图像文件(在apogee中使用文件附件参数,我将其命名为“userfile”)时,我得到了以下响应:
无效的测试URL
我已经为此奋斗了几个小时了,我试着看了代码点火器的文档,但不幸的是,它与API无关,我不知道如何在不使用表单的情况下上传文件。
我不太确定问题是来自我用来测试它的服务apigee,还是来自代码。最后,我的目标是在我正在编写的iPhone应用程序中实现这个函数,但我希望在尝试将它包含在我的应用程序中之前能够测试这个函数。
任何人都可以给予我关于文件上传的信息在一个API?以及如何测试它正确?谢谢。
3条答案
按热度按时间55ooxyrt1#
试试这个,它的工作!
xa9qqrwz2#
试试这个,它可能会帮助你,我做了这个使用codeigniter框架工作,这里是控制器
这是一个视图文件
rlcwz9us3#
它在codeigniter中很简单,您也可以使用此方法,从post中获取数据method=multiform/form-data
并使用此函数上传文件,通过md5更改文件名并将其存储在db中