我在嘗試上傳文件到Titanium appcelerator中的服務器時遇到了很多問題。似乎所有工作都很好,但在服務器中顯示發生了錯誤。這裏是我的鈦代碼:Titanium Appcelerator將圖像上傳到網絡服務器
var win = Ti.UI.createWindow({
backgroundColor : "#FFF"
});
var ind = Titanium.UI.createProgressBar({
width : 200,
height : 50,
min : 0,
max : 1,
value : 0,
style : Titanium.UI.iPhone.ProgressBarStyle.PLAIN,
top : 10,
message : 'Uploading Image',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#888'
});
win.add(ind);
ind.show();
win.open();
Titanium.Media.openPhotoGallery({
success : function(event) {
alert("success! event: " + JSON.stringify(event));
var image = event.media;
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function(e) {
Ti.API.info('IN ERROR ' + e.error);
};
xhr.onload = function() {
Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState);
};
xhr.onsendstream = function(e) {
ind.value = e.progress;
//Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress + ' ' + this.status + ' ' + this.readyState);
};
// open the client
xhr.open('POST', 'http://mypathtotheserver/myphpuploaderfile.php');
xhr.setRequestHeader("Connection", "close");
// send the data
xhr.send({
media : image
});
},
cancel : function() {
},
error : function(error) {
},
allowImageEditing : true
});
,並在服務器上的PHP代碼:
$target_path = "uploads/";
$target_path = $target_path . $_FILES['media']['name'];
if(move_uploaded_file($_FILES['media']['tmp_name'],$target_path)) {
echo "The file ". basename($_FILES['media']['name']).
" has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}
我在做什麼錯?任何幫助,高度讚賞。
預先感謝您!
您好在iOS上工作,但不能在android上工作? wat做什麼?任何暗示 – joe