0

I am trying to connect the android emulator to my localhost (xampp) and send a file to a folder.

I am using the code from slott - wrapping the code up in an Async task to avoid threading errors

and calling it via:

new AsyncHttpPostTask("http://10.0.2.2/android").execute(new File(myFile));

myFile is a valid file with some text

the folder "android" exists directly under the "xampp/htdocs" folder on the c drive

I have added the internet permission in the manifest

I have deleted my AVD and created a new one

XAMPP is running, the path is valid if i open it in a browser e.g. http://localhost/android

After executing the code, i get a "301 Moved Permanently" response from the localhost server

Any ideas on what i have done wrong or how i can investigate further?

==EDIT

I was missing the php file on my path. I am using the following PHP

<?php
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
  echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
  move_uploaded_file ($_FILES['userfile'] ['tmp_name'], $_FILES['userfile'] ['name']);
} else {
  echo "Possible file upload attack: ";
  echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
  print_r($_FILES);
}
?>

I havent used PHP before however i am able to connect now but getting the following error in the response:

Undefined index in the server.php file

Community
  • 1
  • 1
Santiago
  • 982
  • 3
  • 14
  • 30

2 Answers2

1

You need to POST the data, but you will also need a script (probably php since you're using XAMPP) written to accept the post data and save it to that location.

EDIT:

I recommend writing a form to interact with your php script to test if the problem is with your server accepting files.

<form enctype="multipart/form-data" action="http://localhost/android/server.php"; method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 
Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
<input type="submit" value="Upload File" /> 
</form>

Make that page to test uploading files from your computer. Also try it in your AVDs browser.

What I think is your problem is that you're using localhost. You probably need to use your servers public IP address. Look at this: https://stackoverflow.com/a/5224558/1629749

Community
  • 1
  • 1
Tonithy
  • 2,300
  • 1
  • 20
  • 20
  • thank you yes, i forgot to add the server.php file to my path however this results in an issue with the php file. I have edited my question – Santiago Dec 28 '12 at 00:34
0

I modified my PHP code to use MultipartEntity

The emulator was crashing after the PHP changes but this was resolved by deleting my AVD and creating a new one. In addition i restarted my localhost server

Community
  • 1
  • 1
Santiago
  • 982
  • 3
  • 14
  • 30