I thought it worked, but I was wrong.
//Coloca los encabezados
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE');
header('Content-Type: application/json; text/html; charset=UTF-8; multipart/form-data');
header('Access-Control-Max-Age: 3600');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
// Generar archivo .htaccess si es necesario.
ws_htaccess();
$bd = isset($_GET['bd']) ? $_GET['bd'] : null;
if (isset($_FILES['imagen']['name'])) {
$fileName = $_FILES['imagen']['name'];
$tempPath = $_FILES['imagen']['tmp_name'];
// Extensiones validas
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif');
$ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); // toma la extension de la imagen
if (in_array($ext, $valid_extensions)) { // Valida que la extensión sea valida
$ruta = "../../../file/img/".$bd."/imagen";
if (!file_exists($ruta)) {
mkdir($ruta, 0777, true);
}
move_uploaded_file($tempPath, $ruta."/".$fileName);
}
} else {
return getResponse('error', null, 500, 'Fallo en la creación / actualización de la foto');
}