php - 当我将文件上传到服务器时,如何获取文件名?
问题描述
当我将文件上传到服务器时,如何获取文件名?
我用这个方法
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();
}
});
这是php代码
$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)
我可以将文件上传到服务器,但我无法获取文件名
如果文件名为111.MOV,则上传成功,可以在uploads forder中找到111.MOV。
但是,如何获取文件名?
解决方案
推荐阅读
- sql - 有没有办法通过索引优化将 jsonb 值转换为 Posgresql 中的双精度?
- php - 如何防止在php中页面加载/刷新时提交表单?
- excel - 如何在 Excel 文档中使用 VBA 循环浏览超链接
- python - 如何解决 'ImportError: Error importing 'settings': No module named 'basic'' in quepy dbpedia example
- django - AWS Elasticbeanstalk 与 Django:在所有实例上发现不正确的应用程序版本
- metadata-extractor - 在元数据提取器中检测不正确的 makernote 偏移
- sql - 在 Google BigQuery 标准 SQL 中将 1 添加到字符串的时间列
- amazon-web-services - Terraform s3 存储桶生命周期_规则重叠前缀
- python - 网络化 XML 文件到 Python 数据框
- flutter - Flutter 无法调用 setState 重建小部件