Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have the textfile on the SD card, then you can use the following uploading approach to upload the file to your server.</p> <p>You will need a script, such as this PHP script called uploader.php</p> <pre><code> &lt;?php $target_path = "H:/www/yourwebsitedirectory.com/"; $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!"; } ?&gt; </code></pre> <p>Then in your java you can have an Uploader function like this: Make sure to fill in your proper exception handling, and you will need to grab the HTTPClient libraries.</p> <pre><code> public static void Uploader(File fname, String fpath) { try { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); String postURL = "http://www.yourwebsite.com/uploader.php"; HttpPost httppost = new HttpPost(postURL); // the boundary key below is arbitrary, it just needs to match the MPE so it can decode multipart correctly httppost.setHeader("Content-Type", "multipart/form-data; boundary=--32530126183148"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "--32530126183148", Charset.forName("UTF-8")); try { mpEntity.addPart("uploadedfile", new FileBody((fname), "application/txt")); mpEntity.addPart("MAX_FILE_SIZE", new StringBody("100000")); } catch (Exception e1) { } httppost.setEntity(mpEntity); HttpResponse response; try { response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { resEntity.consumeContent(); } } catch (ClientProtocolException e) { } catch (Exception e) { } httpclient.getConnectionManager().shutdown(); } catch (Throwable e) { try { } catch (Throwable e1) { } } } </code></pre> <p>Call the function like this:</p> <pre><code> File tmpDir = new File(android.os.Environment.getExternalStorageDirectory(),"Directory of your file"); File fname = new File(tmpDir, filesnameonSD); Uploader(fname); </code></pre> <p>And to test your PHP script, you can use a webpage with the following simple HTML form</p> <pre><code> &lt;form enctype="multipart/form-data" action="uploader.php" method="POST"&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="100000" /&gt; Choose a file to upload: &lt;input name="uploadedfile" type="file" /&gt;&lt;br /&gt; &lt;input type="submit" value="Upload File" /&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload