Php 改装-将视频上载到XAMPP
我是新来改装的,在过去的两天里遇到了一个大问题。我想将视频从设备摄像头发送到XAMPP服务器 应移动上传视频的php部分:Php 改装-将视频上载到XAMPP,php,post,video,upload,retrofit,Php,Post,Video,Upload,Retrofit,我是新来改装的,在过去的两天里遇到了一个大问题。我想将视频从设备摄像头发送到XAMPP服务器 应移动上传视频的php部分: $returnArray = array(); $videoUploadResult = ""; $target_dir ="/Applications/XAMPP/xamppfiles/htdocs/Projects/Eventtest/videos"; if(!file_exists($target_dir)) { mkdir($target_dir, 0777
$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);
@POST("createEvent.php")
@Multipart
Call<ResponseBody> uploadVideo(@Part MultipartBody.Part file, @Part("filename") RequestBody name);
公共接口服务器接口{
@获取(“getEvents.php”)
调用getEvent(@Query(“result”)字符串标记);
@POST(“createEvent.php”)
//@FormUrlEncoded
@多部分
调用uploadVideo(@Part(“description”)RequestBody description,@Part MultipartBody.Part文件);
代码:
ServerInterface=APIClient.getClient().create(ServerInterface.class);
请求体请求文件=
RequestBody.create(
MediaType.parse(“视频/mp4”),
视频文件
);
多部分主体。部分主体=
MultipartBody.Part.createFormData(“文件名”,videoFile.getName(),requestFile);
//在多部分请求中添加另一部分
String descriptionString=“您好,我是description”;
请求主体描述=
RequestBody.create(
MultipartBody.FORM,descriptionString);
//最后,执行请求
Call Call=serverInterface.uploadVideo(描述,正文);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用,
回应(回应){
Log.v(“上传”、“成功”);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Log.e(“上传错误:,t.getMessage());
}
});
当我通过邮递员发送一个带有键“filename”的视频文件时,php服务器部分工作,如在move_uploaded_file($_FILES[“filename”][“tmp_name”])
我试过不同的例子,这个特别的是
我还尝试发送带有字符串和文件的地图,但没有成功
问题是,日志中没有错误。但我确切地知道,问题在到达move_uploaded_文件($_FILES[“filename”][“tmp_name”])好的,我终于找到了问题和解决方案。 首先,我的XAMPP上的目录videos是只读的。我正在使用Mac,并通过获取信息将文件夹的共享和权限属性更改为读写 其次,我找到了一种将密钥文件对映射到php代码的方法,“filename”是我在move\u上传的\u文件中的密钥($\u FILES[“filename”][“tmp\u name”]: 接口:
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);
@POST("createEvent.php")
@Multipart
Call<ResponseBody> uploadVideo(@Part MultipartBody.Part file, @Part("filename") RequestBody name);
@POST(“createEvent.php”)
@多部分
调用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(“文件名”,videoFile.getName(),requestBody);
RequestBody filename=RequestBody.create(MediaType.parse(“text/plain”)、videoFile.getName();
Call Call=serverInterface.uploadVideo(fileToUpload,文件名);
call.enqueue(……)//onResponse(),onFailure()位于此处
在这里输入代码