Skip to content

Instantly share code, notes, and snippets.

@jonalter
Forked from pec1985/uploadImage.js
Created November 8, 2013 18:38
Show Gist options
  • Save jonalter/7375507 to your computer and use it in GitHub Desktop.
Save jonalter/7375507 to your computer and use it in GitHub Desktop.
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