Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Android:使用MultipartEntity上传大文件_Php_Android_Upload_Multipartform Data_Multipart - Fatal编程技术网

Php Android:使用MultipartEntity上传大文件

Php Android:使用MultipartEntity上传大文件,php,android,upload,multipartform-data,multipart,Php,Android,Upload,Multipartform Data,Multipart,根据这个答案,我做所有的步骤 但我不知道如何为服务器端编写代码!我的意思是一个PHP简单的页面,为我最喜欢的上传服务 另一个问题是:您的URL(以下代码段的第三行)必须是该PHP页面的地址 private void uploadVideo(String videoPath) throws ParseException, IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost

根据这个答案,我做所有的步骤

但我不知道如何为服务器端编写代码!我的意思是一个PHP简单的页面,为我最喜欢的上传服务

另一个问题是:您的URL(以下代码段的第三行)必须是该PHP页面的地址

private void uploadVideo(String videoPath) throws ParseException, IOException {

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(YOUR_URL);

    FileBody filebodyVideo = new FileBody(new File(videoPath));
    StringBody title = new StringBody("Filename: " + videoPath);
    StringBody description = new StringBody("This is a description of the video");

    MultipartEntity reqEntity = new MultipartEntity();
    reqEntity.addPart("videoFile", filebodyVideo);
    reqEntity.addPart("title", title);
    reqEntity.addPart("description", description);
    httppost.setEntity(reqEntity);

    // DEBUG
    System.out.println( "executing request " + httppost.getRequestLine( ) );
    HttpResponse response = httpclient.execute( httppost );
    HttpEntity resEntity = response.getEntity( );

    // DEBUG
    System.out.println( response.getStatusLine( ) );
    if (resEntity != null) {
      System.out.println( EntityUtils.toString( resEntity ) );
    } // end if

    if (resEntity != null) {
      resEntity.consumeContent( );
    } // end if

    httpclient.getConnectionManager( ).shutdown( );
}

此代码工作正常,我应该使用的PHP代码如下所示:

<?php

    $file_path = "uploads/";

    $file_path = $file_path . basename( $_FILES['videoFile']['name']);
    if(move_uploaded_file($_FILES['videoFile']['tmp_name'], $file_path)) {
        echo "success";
    } else{
        echo "upload_fail_php_file";
    }
 ?>

注意该视频文件必须与

reqEntity.addPart(“视频文件”,filebodyVideo)

您可能面临的最重要的问题是服务器配置中的
post_max_size
upload_max_filesize
的默认值!由于默认值太小,当您尝试上载大文件时,PHP脚本返回:“upload\u fail\u PHP\u file”,没有错误或异常抛出因此请记住将这些值设置为足够大的值

享受编码