2
I took a script (Java android e php) from a book I’m studying, which simply takes a photo sent from android and saved in a folder on my server.
The android application ran without any error, but I ended up encountering an error in the php file:
if ($_FILES["arquivo"]["error"] > 0) {
// Bad Request
http_response_code(400);
} else {
$arquivo_destino = "imagens/" . $_POST["titulo"] . ".jpg";
if (file_exists($arquivo_destino)) {
http_response_code(501);
} else {
move_uploaded_file(
$_FILES["arquivo"]["tmp_name"],
$arquivo_destino
);
http_response_code(200);
}
}
Error happens in function http_response_code(400)
, searching the net I read something saying that this function only works in php 5.4 or higher (I’m not sure if this is true), so I was wondering if you have any alternative function for my version of php 5.2.17.
For those who did not understand what I’m trying to do, I’m sending a photo by android and returning an http code according to what happens there on the server in the php file (if there is an error with the file returns 400, if there already exists a file with the same name returns 501, and if it occurs all right returns 200).
I know you’re just studying, but always use the newest version of PHP. This is a golden tip http://br.phptherightway.com/
– Renato Tavares
I am using the Ocaweb server of my work and it seems that it only has php 5.2.17.
– Bruno Romualdo
Follows Alternative to http_response_code in PHP versions below 5.4
– Guilherme Nascimento