I'm trying to upload a Base64 encoded .Png file to a PHP server from an Android application.
Below code doesn't return anything in the response. What am I doing wrong?
I'm sending the Base64 encoded string and the name of the file. (ex:"sign1234.png")
<?php
if(isset($_POST['image']) && isset($_POST['name']){
$image = $_POST['image'];
$name = $_POST['name'];
$png = base64_to_jpeg($image,$name);
$target = 'uploads/'.$name;
$result = move_uploaded_file( $_FILES['$png']['tmp_name'], $target);
if($result){
$response["success"] = 1;
$response["message"] = "Upload Successful.";
echo json_encode($response);
}else{
$response["success"] = 0;
$response["message"] = "Server error. Could not upload.";
echo json_encode($response);
}
}
function base64_to_jpeg($base64_string, $output_file) {
$ifp = fopen($output_file, "wb");
$data = explode(',', $base64_string);
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $output_file;
}
?>