将视频上传到XAMPP

我是翻新新手,在过去的2天里遇到了很大的问题。 我想从我的设备相机发送视频到XAMPP服务器。

PHP部分上传的视频应该移动的地方:

$returnArray = array();
$videoUploadResult = "";

$target_dir ="/Applications/XAMPP/xamppfiles/htdocs/Projects/Eventtest/videos";
if(!file_exists($target_dir)) {
   mkdir($target_dir, 0777, true);
}

$target_file_name = $target_dir . "/" . basename($_FILES["filename"]["name"]);


if(move_uploaded_file($_FILES["filename"]["tmp_name"], $target_file_name)) {
    $returnArray["video_upload_status"] = "Video uploaded successfully";
} else {
    $returnArray["status"] = 400;
    $returnArray["message"] = "Couldn't upload the video";

    echo json_encode($returnArray);
}
exit;

接口:

public interface ServerInterface {
   @GET("getEvents.php")
   Call<List<JSONData>> getEvent(@Query("result") String tag);

   @POST("createEvent.php")
   //@FormUrlEncoded
   @Multipart
   Call<ResponseBody> uploadVideo(@Part("description") RequestBody description, @Part MultipartBody.Part file); 

码:

ServerInterface = APIClient.getClient().create(ServerInterface.class);


    RequestBody requestFile =
            RequestBody.create(
                    MediaType.parse("video/mp4"),
                    videoFile
            );
    MultipartBody.Part body =
            MultipartBody.Part.createFormData("filename", videoFile.getName(), requestFile);

    // add another part within the multipart request
    String descriptionString = "hello, this is description speaking";
    RequestBody description =
            RequestBody.create(
                    MultipartBody.FORM, descriptionString);

    // finally, execute the request
    Call<ResponseBody> call = serverInterface.uploadVideo(description, body);
    call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call,
                               Response<ResponseBody> response) {
            Log.v("Upload", "success");
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.e("Upload error:", t.getMessage());
        }
    });

当我用密钥“文件名”通过邮递员发送视频文件时,php服务器部分工作,如move_uploaded_file($ _ FILES [“filename”] [“tmp_name”]。

我已经尝试了不同的例子,这个特殊的是从https://futurestud.io/tutorials/retrofit-2-how-to-upload-files-to-server我也试着发送一个带有字符串和文件的地图,但没有成功。

问题是,日志中没有错误。 但我确切地知道,一旦它到达move_uploaded_file($ _ FILES [“filename”] [“tmp_name”]


好的,我终于找到了问题和解决方案。 首先,我的XAMPP上的目录视频是只读的。 我正在使用Mac并将文件夹的“共享和权限”属性更改为“通过获取信息进行读取和写入

其次,我找到了一种方法来映射密钥文件对我的PHP代码,“文件名”是我在move_uploaded_file($ _ FILES [“文件名”] [“tmp_name的值”]:界面:

@POST("createEvent.php")
@Multipart
Call<ResponseBody> uploadVideo(@Part MultipartBody.Part file, @Part("filename") RequestBody name);

码:

    serverInterface = APIClient.getClient().create(ServerInterface.class);
    RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), videoFile);
    MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("filename", videoFile.getName(), requestBody);
    RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), videoFile.getName());


    Call<ResponseBody> call = serverInterface.uploadVideo(fileToUpload, filename);
call.enqueue(......) // onResponse(), onFailure() goes here
enter code here
链接地址: http://www.djcxy.com/p/75393.html

上一篇: upload video to XAMPP

下一篇: Unspecified error with a file upload loop