我正在尝试将 sqlite 数据库从我的 android 手机发送到 Web 服务器。代码执行时我没有收到任何错误,但是数据库没有出现在服务器上。这是我的 php 代码和从 android 手机上传文件的代码。连接响应消息是“OK”,我得到的来自 http 客户端的响应是 org.apache.http.message.BasicHttpResponse@4132dd40。
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";
}
?>