2
我想從我的android手機發送一個sqlite數據庫到一個web服務器。代碼執行時不會出現錯誤,但數據庫不會顯示在服務器上。這裏是我的php代碼和代碼從android手機上傳文件。連接響應消息get是「OK」,我從http客戶端得到的響應是[email protected]。試圖從android手機發送sqlite數據庫到web服務器
public void uploadDatabase() {
String urli = "http://uploadsite.com";
String path = sql3.getPath();
File file = new File(path);
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urli);
URL url = new URL(urli);
connection = (HttpURLConnection) url.openConnection();
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);
HttpResponse response = httpclient.execute(httppost);
String response2 = connection.getResponseMessage();
Log.i("response", response.toString());
Log.i("response", response2.toString());
} catch (Exception e) {
}
}
<?php
$uploaddir = '/var/www/mvideos/uploads/';
$file = basename($_FILES['userfile']['name']);
$timestamp = time();
$uploadfile = $uploaddir . $timestamp . '.sq3';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "OK";
} else {
echo "ERROR: $timestamp";
}
?>
你是否得到這個工作。如果是這樣的話。我需要做同樣的事情。 – lastshadowrider 2012-05-09 19:25:30
是的,我沒有確切的代碼,但我把下面的樣本放在了我的基礎上。 – johns4ta 2012-05-10 18:27:03