Why is impossible loading pictures from Android phone to a server using php script?
It was working good in past hosting cPanel managed server, but they vanished away with all my data and work.
When I translate my site to other new hosting cPanel managed server too, the phone app stop working.
The returned message of the script is “Empty file”.
Any one has almost an explanation?
There are three parts to your issue:
- Your app setup
- Your php file
- Your server / hosting
Start in reverse, check your server is setup correctly, check your php file is correct, check your app is sending the file correctly.
Alternatively, show eveything here.
PHP script:
<?php
if($datos_archivo = file_get_contents('php://input')){
$nombreArchivo = 'foto_' . time() . '.jpg';
$rutaCompleta = 'uploads/' . $nombreArchivo;
if (!is_dir('uploads')) {
mkdir('uploads', 0777, true);
}
if ($datos_archivo !== false && strlen($datos_archivo) > 0) {
if (file_put_contents($rutaCompleta, $datos_archivo)) {
echo json_with_status("success","Archivo guardado con exito.",$nombreArchivo);
} else {
echo json_with_status("error","Ocurrio un error al guardar el archivo.","");
}
} else {
echo json_with_status("error","No se envio ningun archivo o el cuerpo esta vacio.","",$nombreArchivo);
}
function json_with_status($status, $mensaje, $nombre, $nombreFalso) {
header('Content-Type:application/json');
return json_encode(["status" => $status,"mensaje" => $mensaje,"nombre" => $nombre,"nombreFalso" => $nombreFalso]);
}
} else {
echo "El contenido está vacío.";
}
?>
App Inventor blocks:
Message from the php script:
Thank you for your help.
Your php script works ok on my server ( uploaded a couple of images ).
I checked also with a small script I use to verify headers/parameters ( useful to understand if the problem is client/server side ), here the result:
web04.aia (2.6 KB)
params.txt (2.9 KB)
The return message is shorter that the one you have show before.
I think that the real problem is at “[Transfer-Encoding] => chunked”. App Inventor PostFile block sends nothing, but about that I couldn.t find documentation:
”2026-06-16 16:23:20
headers:
Array
(
[X-Https] => 1
[Accept-Encoding] => gzip
[Connection] => Keep-Alive
[Host] => www.mydomain.com
[User-Agent] => Dalvik/2.1.0 (Linux; U; Android 10; AQM-LX1 Build/HUAWEIAQM-LX1)
[Transfer-Encoding] => chunked
[Content-Type] => image/jpeg
)
GET params:
Array
(
)
POST params:
Array
(
)”
This is the reason because I said it’s “Impossible”.
Nobody knows how to solve this irritating issue with App Invertor.
Two methods I have used without issue personally though others have had trouble with the first one.
see my comment regarding some hosting providers not allowing file_get_contents


