如何解决发送API数据和图像,但始终为空
我正在尝试使用Slim 3,PHP 7和JQuery 2.1.1将用户图片发送到我的api 但是,当我在HTML页面中调用api时,我在Apache日志中遇到了一些错误,看来数据参数为空,我也不知道为什么。 有人可以帮忙吗?
-------HTML source code api call
function savePicture(){
var fID = $('#edtIDUser').val();
var fPicture = document.getElementById('img').src;
$.ajax({
type:"POST",cache:false,url:"index.php/user_picture/",timeout:3000,contentType:"application/json; charset=utf-8",data:{'id_user': fID,'picture': fPicture},dataType:"text",async:false,error: function (request,error) {
alert("error");
},success: function (result) {
alert("ok");
}
});
}
AND API
----API source code
$app->post('/user_picture/',function(Request $request,Response $response) {
$params = $request->getParsedBody();
$iduser = $params['id_user'];
$uploadedFile = $request->getUploadedFiles();
$img = $uploadedFile['picture'];
$data = file_get_contents($img);
$escaped = bin2hex($data);
//TO-DO
}
错误1:尝试在$ params ['id_user']中访问类型为null的值的数组偏移量 错误2:未定义索引“图片” 错误#3:file_get_contents():文件名不能为空
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。