Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

image uploading problem

$
0
0

Hello guys, Im trying to send an image from iphone to server. It seems everything is ok. but when i run it I get html codes in alert window and it says "page not found". Im sending my codes. could you please check that where I made a mistake. thank you very much.

var win = Titanium.UI.createWindow({
    top:0,
    left:0,
    width:150
});
 
 
Titanium.Media.openPhotoGallery({
 
success:function(event){
 
    if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO){
        // the image
        var image = event.media;
 
        var tempImageView = Titanium.UI.createImageView({
            image:image
        });
        win.add(tempImageView);
 
        var image2 = tempImageView.toImage();
 
        var dataToSend = { media : image2
                        ,title : 'asd'};
 
        var xhr = Titanium.Network.createHTTPClient();
 
        xhr.open("POST","http://kodpenceresi.com/upload.php");
        xhr.onload = function(){
           alert(this.responseText);
        };
 
        xhr.send(dataToSend);
 
    }
},
        cancel : function() {
 
            alert("Cancel Library ");
        },
        error : function(error) {
 
            alert("Error Massage "+error);
        },
        mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],
        allowImageEditing:true,
 
       });
 
win.open();

Here is the php code for saving image...

<?php
    //get file ext
    $ImageType = @explode('/',$_FILES['media']['type']);
 
    //create unique name
    $randName = md5(time());
    $newName= $randName.'.'.$ImageType[1];
 
    //upload dir
    $target = 'images/';
    $target = $target . $newName;
 
    //move the file
    if(move_uploaded_file($_FILES['media']['tmp_name'],$target)){
        echo 'success';
    }else{
        echo 'failed';
    }
?>

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>