3
我终于开始使用Titanium Mobile开发iPhone应用程序。现在我面对的问题是,我能够运行该应用程序,并且该应用程序还将该映像发送到服务器。但我无法看到上传到服务器的文件。我粘贴了iPhone应用程序的代码以将图像发送到服务器,并且还将从应用程序接收文件的PHP文件。如何从使用钛开发的iPhone应用程序上传图像
var win = Titanium.UI.currentWindow;
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();
Titanium.Media.openPhotoGallery({
success:function(event)
{
Ti.API.info("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://www.myserver.com/tmp/upload2.php');
xhr.setRequestHeader("Connection", "close");
// send the data
xhr.send({media:image});
},
cancel:function()
{
},
error:function(error)
{
},
allowImageEditing:true
});
这里是服务器上的PHP代码:http://www.pastie.org/891050
我不知道我要去哪里错了。请帮我解决这个问题。如果您需要更多信息,愿意提供。
嗨, 谢谢!现在它工作正常!但我不能得到扩展名的文件!就像iPhone一样,iPhone上传的图片没有任何独特的名称或扩展名! – 2010-04-11 05:17:26