Android allow multiple file upload (Max 150 MB) to PHP Server Android allow multiple file upload (Max 150 MB) to PHP Server android android

Android allow multiple file upload (Max 150 MB) to PHP Server


I have a project which can upload image/file size of up to 48-50 MB. [I'm using Retrofit for Network communication.]Here is the link to the Sample Project: https://github.com/DearDhruv/Retrofit-with-EventBus

Here is code:

private void startUploading(final File file) {    if (file == null || !isPictureValid(file.getAbsolutePath())) {        showMsg("File is not valid, try again.");    } else if (file.exists()) {        showProgressDialog();        String mimeType = "image/jpeg"                // "application/octet-stream"                // "multipart/form-data"                // "image/*"                // "multipart/mixed"                ;        TypedFile typedFile = new TypedFile(mimeType, file);        mApiClient.uploadFile(UPLOAD_FILE_REQUEST_TAG, typedFile);    } else {        showMsg("File is corrupted.");    }}

Here is server-side code:

class ImageUploadStatus {    public $result_code = 0;    public $message = "Image upload failed.";}    class ImageResults {    public $name = "";    public $url = "";    public $size = "";}$status = new ImageUploadStatus ();$results = new ImageResults ();if ($_FILES ["file"] ["error"] > 0) {    header ( "HTTP/1.1 400 Bad Request" );    // echo "Error: " . $_FILES ["file"] ["error"] . "<br /> \n";    $status->message = "Error: " . $_FILES ["file"] ["error"];} else {    if ($_FILES ["file"] ["error"] > 0) {        // echo "Error: " . $_FILES ["file"] ["error"] . "<br /> \n";        $status->message = "Error: " . $_FILES ["file"] ["error"];    } else {        // echo "Upload: " . $_FILES ["file"] ["name"] . "<br /> \n";        // echo "Type: " . $_FILES ["file"] ["type"] . "<br /> \n";        // echo "Size: " . ($_FILES ["file"] ["size"] / 1024) . " Kb<br /> \n";        // echo "Stored in: " . $_FILES ["file"] ["tmp_name"] . "<br /> \n";    }    $target_path = "../api/uploads/";    $target_path = $target_path . basename ( $_FILES ['file'] ['name'] );    //if (is_uploaded_file ( $_FILES ['uploadedfile'] ['tmp_name'] )) {        // echo "There was an error uploading the file, please try again!";        //$status->message = "There was an error uploading the file, please try again!";    //}    if (move_uploaded_file ( $_FILES ['file'] ['tmp_name'], $target_path )) {        // echo "The file " . basename ( $_FILES ['file'] ['name'] ) . " has been uploaded";        $status->message = "Image upload successful";        $status->result_code = 1;        $results->name = $_FILES ["file"] ["name"] . "";        $results->url = $target_path . "";        $results->size = ($_FILES ["file"] ["size"] / 1); // 1024 to convert in KB    } else {        // echo "There was an error Moving the file, please try again!";        //$status->message = "There was an error Moving the file, please try again!";         switch($_FILES['file']['error']){            case 0: //no error; possible file attack!              $status->message =  "There was a problem with your upload.";              break;            case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini              $status->message =  "The file you are trying to upload is too big.";              break;            case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form              $status->message =  "The file you are trying to upload is too big.";              break;            case 3: //uploaded file was only partially uploaded                $status->message =  "The file you are trying upload was only partially uploaded.";              break;            case 4: //no file was uploaded              $status->message =  "You must select an image for upload.";              break;            default: //a default error, just in case!  :)              $status->message =  "There was a problem with your upload.";              break;          }        }    $response = array (            'status' => $status,            'results' => $results     );    // echo (json_encode ( $status ));    // echo (json_encode ( $results ));    echo (json_encode ( $response ));}

I guess this might be helpful.

You might also need to give the max size of upload file in PHP configuration.


Please check these two settings in php.ini file on your server which handles file upload.

; Maximum allowed size for uploaded files.upload_max_filesize = 150M; Must be greater than or equal to upload_max_filesizepost_max_size = 150M

You need to make these settings proper first on your server then only big file upload will work properly.Also check the settings on your local server. These settings are more important before writing the code to handle upload because your code is correct according to me as file upload is working for you. The problem seems to be with php.ini settings....