【发布时间】:2015-11-08 12:43:05
【问题描述】:
我正在尝试将带有一些附加数据的图像发送到服务器。我的问题是图像没有保存在其他记录所在的服务器上。
下面是我的 .html 代码:
<div class="widget uib_w_4 d-margins" data-uib="media/file_input" data-ver="0">
<input type="file" name="image" id="image"
accept="image/jpeg, image/png, image/gif"
ng-model="image" class="ng-pristine ng-untouched ng-valid">
</div>
<div class="widget uib_w_5 d-margins" data-uib="media/text" data-ver="0">
<div class="widget-container left-receptacle"></div>
<div class="widget-container right-receptacle"></div>
<div>
<p>Username:</p>
</div>
</div>
JS 代码
< script >
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$scope.SendData = function()
var data = $.param({
image: $scope.image,
username: $scope.username,
});
var config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;
charset = utf - 8;
'
}
}
var param = getParameterByName('id');
$http.post('myrurl.php', data, config)
.success(function(data, status, headers, config) {
window.location.href = 'view.html';
})
.error(function(data, status, header, config) {
alert('Please retry');
});
};
});
< /script>
我尝试使用 print_r($_REQUEST); 在 PHP 中打印值
image的值为null。
如何将我的图像发送到服务器?
【问题讨论】:
-
如何处理服务器端的事情?
-
服务器代码很好我试图通过打印请求检查图像值是否为空白
-
我在服务器上使用单独的 enpoint 仅用于图像上传。用户必须先上传图片,然后发送表单数据。但无论哪种方式,我都会在将图片发送到服务器之前将其准备为 formData
-
你可以创建小提琴示例或指导我示例 url,但我不想作为两个请求发送
标签: javascript angularjs