when I upload the file to server, how can get the file name?
I use this method
Map<String, RequestBody> map = new HashMap<>();
//File file = new File(newvideoPath);
String fullFilePath = PathUtil.getPathFromUri(this,contentURI);
// Parsing any Media type file
File file = new File(fullFilePath);
RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
map.put("file\"; filename=\"" + file.getName() + "\"", requestBody);
ApiConfig getResponse = AppConfig.getApiClient().create(ApiConfig.class);
Call<ServerResponse> call1 = getResponse.upload("token", map);
call1.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
if (response.isSuccessful()){
if (response.body() != null){
progressDialog.dismiss();
ServerResponse serverResponse = response.body();
Toast.makeText(getApplicationContext(), serverResponse.getMessage(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(UploadActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}else {
Toast.makeText(getApplicationContext(), "problem uploading video", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
Log.v("Response gotten is", t.getMessage());
Toast.makeText(getApplicationContext(), "problem uploading video " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
and this is php code
$target_dir = "uploads/";
$target_file_name = $target_dir .basename($_FILES["file"]["name"]);
$response = array();
$video_path = basename($_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file_name)
I can upload the file to server, but I cannot get the file name
if the file name is 111.MOV, the upload successful, it's can find 111.MOV in uploads forder.
but, how can get the file name?