views:

794

answers:

4

Hi, I finally landed up in developing an iPhone app using Titanium Mobile. Now the problem I face is, Im able to run the app, and the app also sends the image to the server. But Im not able to see the file that got uploaded to the server. I have pasted the iPhone app's code to send image to the server and also, the PHP file that would receive the file from the app.

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
});

And here is the PHP code on the server: http://www.pastie.org/891050

I'm not sure where I'm going wrong. Please help me out in this issue. Would love to provide if you need some more information.

A: 

Hello Kartik,

I am facing same problem,I have written same code that you had written,but when I called this file in my app. photo gallery doesn't open, only I can see progress bar in new window Code I have written in app.js is :

Titanium.App.addEventListener('recordvideo', function(e) { win1.close(); // alert(Titanium.Platform.name); var w = Titanium.UI.createWindow({ backgroundColor:'#336699', title:'Modal Window', barColor:'black', url:'xhr_testfileupload.js' });

w.open({animated:true});

});

Can you please help me regarding this issue?

Hi,Sorry but Im not very clear about the error you get ! Can you be much more elaborate? Or a screenshot should do!
Karthik.K
+1  A: 

Hello kartik,

 use following code for 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!";
}
Hi,Thanks! And Now it works fine! But Im not able to get the file with extension! As in, the iPhone uploads the images without any unique name or extension!
Karthik.K
A: 

Hello Kartik,

  You have solved this problem?
Nope! I haven't! :(
Karthik.K
A: 

i have same problem too...

are you have solved this issue??

Wilson