繁体   English   中英

如何从使用Titanium开发的iPhone应用程序上传图像

[英]How to upload images from iPhone app developed using Titanium

我终于开始使用Titanium Mobile开发iPhone应用程序了。 现在我遇到的问题是,我能够运行应用程序,应用程序也将图像发送到服务器。 但我无法看到上传到服务器的文件。 我已粘贴iPhone应用程序的代码将图像发送到服务器,以及将从应用程序接收文件的PHP文件。

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

我不确定我哪里出错了。 请帮我解决这个问题。 如果您需要更多信息,愿意提供。

使用以下代码为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!";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM