视频没有从android上传到php服务器使用改造

qgzx9mmu  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(320)

我正在尝试用xampp从android上传一个视频到服务器和我的数据库,但是当我尝试上传时,既没有上传视频,也没有收到错误,甚至连视频的url都被上传了。我用改装上传。

if (!videoPath.isEmpty()) {
                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl(Constants.ROOT_URL)
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();

                File file = new File(videoPath);

                RequestBody requestBody = RequestBody.create(MediaType.parse("video/*"), file);

                MultipartBody.Part video = MultipartBody.Part.createFormData("vid", file.getName(), requestBody);

                RequestBody requestEmail = RequestBody.create(MediaType.parse("text/plain"), userEmail);

                MultipartBody.Part email = MultipartBody.Part.createFormData("email", userEmail, requestEmail);

                String todayDate = postFormatDate(new Date());
                RequestBody requestDate = RequestBody.create(MediaType.parse("text/plain"), todayDate);

                MultipartBody.Part date = MultipartBody.Part.createFormData("today_date", todayDate, requestDate);

                RetrofitApi service = retrofit.create(RetrofitApi.class);
                Call<ResponseBody> call = service.uploadVideo(video, email, date);

                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        t.printStackTrace();
                        Toast.makeText(PostActivity.this, getString(R.string.server_error), Toast.LENGTH_SHORT).show();
                    }

                });

            }

我的改装界面:

@Multipart
@POST("post_video.php")
Call<ResponseBody> uploadVideo(@Part MultipartBody.Part video, @Part MultipartBody.Part email, @Part MultipartBody.Part today_date);

以及我的php代码:

if (isset($_FILES['vid']['name'])) {

$path = 'Images/';

$server_ip = gethostbyname(gethostname());

$url = 'http://' . $server_ip .'/folder/' . $path;

$con3 = new mysqli($host,$username,$password,$database);

$extension3 = pathinfo($_FILES['vid']['name'],PATHINFO_EXTENSION);

$file_url = $url . getFileName() . '.' . $extension3;
$file_path = $path . getFileName() . '.' . $extension3;

try {

    move_uploaded_file($_FILES['vid']['tmp_name'], $file_path);

    $date = $_FILES['today_date']['name'];

    $sql3 ="INSERT INTO posts_media_files (url, post_id,date) VALUES ('$file_url','$id_bind','$date');";
    $stm3 = $con3->prepare($sql3);

    $stm3->execute();

}

}

我的xampp上传文件限制是200mb(我确实增加了它)。请帮帮我,我真的很累!。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题