我在尝试将文件上传到 WebServer 时遇到问题。
这是我正在使用的代码:
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")
.
有什么问题?