Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created April 27, 2011 02:56
Show Gist options
  • Save pec1985/943640 to your computer and use it in GitHub Desktop.
Save pec1985/943640 to your computer and use it in GitHub Desktop.
Upload Image
Titanium.Media.openPhotoGallery({
success:function(event){
var myImage = event.media;
var xhr = Titanium.Network.createHTTPClient();
xhr.open('POST','http:// ------ /uploads.php');
xhr.onerror = function(e){alert(e.error);};
xhr.setTimeout(200000);
xhr.onload = function(e){
Ti.UI.createAlertDialog({title:'Success', message: this.responseText
}).show();};
xhr.onsendstream = function(e){Ti.API.info(e);};
xhr.setRequestHeader("contentType", "multipart/form-data");
xhr.send({uploadedfile:myImage});
},
cancel:function(){
},
error:function(error){
},
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment