1
我試圖將文件上傳到WebServer時遇到問題。嘗試將文件上傳到Apache服務器時出現Android問題
這是我使用的代碼:
File file = new File(fileUri.getPath());
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL_connect);
Log.e("subiendo archivo",fileUri.getPath());
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
e.printStackTrace();
Toast toast1 = Toast.makeText(getApplicationContext(),"Error "+e, Toast.LENGTH_SHORT);
toast1.show();
Vibrator vibrator =(Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(200);
}
但是沒有辦法,文件沒有被上傳到服務器,我在服務器端嘗試這樣的:
$file = $_FILES["file"];
$nombre_archivo = $_FILES['file']['name'];
$tipo_archivo = $_FILES['file']['type'];
$tamano_archivo = $_FILES['file']['size'];
$temporal = $_FILES['file']['tmp_name'];
move_uploaded_file($temporal, "../img/media/".$nombre_archivo);
在LogCat中沒有關於上傳的內容,它只是打印Log.e("uploading file","name and path of the file")
。
有什麼問題?
我得到145 HTTP錯誤與此代碼 – SkyHunter
是的,我幾個月前,我已經添加了答案和正確的代碼,您可以在下面看到它。 –