Sunday , January 16 2022

Android Upload File to Server with Progress using Retrofit – Android Coding by DMTechnolab


// getting database connection

the wanted_Once ‘DbConnect.php’;

// array to show the response

$Feedback = Array());

// uploads the directory, we will upload all the files inside this folder

$target_dir = “Upload /”;

// checking if we are receiving an epi call, using the received parameters ‘Epicall’


to switch()$_get[‘apicall’]){{

// if there is an API call to upload the image

matter ‘Pour’:

// error message and error flag

$message = ‘Ultimate’;

$is_error = false;

// Verifying the request to check if all the required parameters are available


$message .= “Descend,”;

$is_error = True;



$message .= “Image”;

$is_error = True;


// If we have validation error, error message is displayed


$Feedback[‘error’] = True;

$Feedback[‘message’] = $message . “Is necessary.”;


// if validation is successful

// Create a target file with a unique name, so that for every upload we create a unique file in our server

$target file = $aim_you . Bodiless()) . .pathinfo()$_FILES[‘image’][‘name’], Pathinfo_sension);

// save the uploaded file to our target file in the upload directory

If ()Move_uploaded_file()$_FILES[“image”][“tmp_name”], $target file)) {{

// saving the file information to our database

$stmt = $Who->ready()“INSERT INTO UPLOAD (` PATH`, `DETAILS`) VALVE (?)?”);

$stmt->bind_param()“ss”, $target file, $_Post[‘desc’]);

// if it is successfully saved in database


// Displaying success response

$Feedback[‘error’] = false;

$Feedback[‘message’] = ‘Image uploaded successfully’;

$Feedback[‘image’] = getBaseURL()) . $target file;


// if database is not saved

// showing response accordingly

$Feedback[‘error’] = True;

$Feedback[‘message’] = ‘Could not upload image, try again …’;



} other {{

$Feedback[‘error’] = True;

$Feedback[‘message’] = ‘try again later…’;




// We will use this case to get all uploaded images from the database

matter ‘Images’:

$stmt = $Who->ready()“Select` id`,` path`, `description` from upload”);


$stmt->bind_result()$Id, $The path, $Descend);


$The image = Array());

$The image[‘id’] = $Id;

$The image[‘path’] = getBaseURL()) . $The path;

$The image[‘desc’] = $Descend;

array_push()$Feedback, $The image);




$Feedback[‘error’] = True;

$Feedback[‘message’] = ‘Invalid operation called’;



$Feedback[‘error’] = True;

$Feedback[‘message’] = ‘Invalid API Call’;


The ceremony getBaseURL()){{

$url = disturbed()$_SERVER[‘HTTPS’]) The ‘https: //’ : ‘http://’;

$url .= $_SERVER[‘SERVER_NAME’];

$url .= $_SERVER[‘REQUEST_URI’];

The return dirname()$url) . ‘/’;


Header()‘Content-Type: application / json’);

Echo json_encode()$Feedback);

Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *