";
echo "
🔧 Diagnóstico API";
echo "";
echo "🔧 DIAGNÓSTICO DE LA API
";
echo "Ejecutándose desde: " . __DIR__ . "
";
// 1. Verificar estructura de carpetas
echo "";
echo "
📁 ESTRUCTURA DE ARCHIVOS...
";
// Verificar que existe la carpeta api
if (!is_dir('api')) {
echo "
❌ CRÍTICO: Carpeta 'api' no encontrada
";
exit;
}
echo "
✅ Carpeta 'api' encontrada
";
// Verificar config desde diferentes ubicaciones
$config_paths = [
'config/config.php' => 'Ruta desde raíz',
'api/../config/config.php' => 'Ruta desde API (relativa)',
'../config/config.php' => 'Ruta desde API (parent)'
];
foreach ($config_paths as $path => $desc) {
if (file_exists($path)) {
echo "
✅ $desc: $path existe
";
} else {
echo "
❌ $desc: $path NO existe
";
}
}
echo "
";
// 2. Listar archivos de la API
echo "";
echo "
📋 ARCHIVOS DE LA API...
";
$api_files = glob('api/*.php');
if (empty($api_files)) {
echo "
❌ No se encontraron archivos PHP en la API
";
exit;
}
echo "
✅ Encontrados " . count($api_files) . " archivos en la API:
";
foreach ($api_files as $file) {
$filename = basename($file);
$size = filesize($file);
$readable = is_readable($file) ? '✅' : '❌';
echo "
$readable $filename ($size bytes)
";
}
echo "
";
// 3. Analizar el primer archivo de API
echo "";
echo "
🔍 ANÁLISIS DEL PRIMER ARCHIVO...
";
$test_file = $api_files[0];
$filename = basename($test_file);
echo "
Analizando: $filename
";
$content = file_get_contents($test_file);
if (!$content) {
echo "
❌ No se pudo leer el archivo
";
} else {
// Buscar require_once
if (preg_match('/require_once\s+[\'"]([^\'"]+)[\'"]/', $content, $matches)) {
$required_path = $matches[1];
echo "
🔗 Requiere: $required_path
";
// Verificar si la ruta existe desde la perspectiva del archivo API
$full_path_from_api = 'api/' . $required_path;
$parent_path_from_api = dirname('api/' . basename($test_file)) . '/' . $required_path;
if (file_exists($required_path)) {
echo "
✅ Ruta directa '$required_path' existe
";
} elseif (file_exists($full_path_from_api)) {
echo "
⚠️ Ruta '$required_path' existe como '$full_path_from_api'
";
} else {
echo "
❌ Ruta '$required_path' NO existe
";
echo "
❌ Tampoco existe como '$full_path_from_api'
";
}
} else {
echo "
⚠️ No se encontró require_once en el archivo
";
}
}
echo "
";
// 4. Test de carga de configuración DESDE la API
echo "";
echo "
⚙️ TEST CARGA CONFIG DESDE API...
";
// Simular estar en la carpeta API
$original_dir = getcwd();
try {
// Cambiar al directorio API
chdir('api');
echo "
📁 Cambiado a directorio: " . getcwd() . "
";
// Intentar cargar configuración con diferentes rutas
$config_attempts = [
'../config/config.php' => 'Ruta parent (.../config/config.php)',
'config/config.php' => 'Ruta directa (config/config.php)',
'../config.php' => 'Config en raíz (../config.php)'
];
$config_loaded = false;
foreach ($config_attempts as $path => $desc) {
echo "
🔄 Probando: $desc
";
if (file_exists($path)) {
echo "
✅ Archivo existe: $path
";
try {
// Capturar errores
ob_start();
$error_before = error_get_last();
include_once $path;
$output = ob_get_clean();
$error_after = error_get_last();
if ($error_after && $error_after !== $error_before) {
echo "
❌ Error cargando: " . htmlspecialchars($error_after['message']) . "
";
} else {
echo "
✅ Config cargado desde: $path
";
$config_loaded = true;
// Verificar algunas constantes
$test_constants = ['DB_HOST', 'DB_NAME', 'DB_USER'];
foreach ($test_constants as $const) {
if (defined($const)) {
echo "
✅ $const definido
";
} else {
echo "
❌ $const no definido
";
}
}
break;
}
} catch (Exception $e) {
echo "
❌ Excepción: " . htmlspecialchars($e->getMessage()) . "
";
}
} else {
echo "
❌ Archivo no existe: $path
";
}
}
if (!$config_loaded) {
echo "
❌ CRÍTICO: No se pudo cargar ninguna configuración
";
}
} catch (Exception $e) {
echo "
❌ Error general: " . htmlspecialchars($e->getMessage()) . "
";
} finally {
// Volver al directorio original
chdir($original_dir);
echo "
📁 Vuelto a directorio: " . getcwd() . "
";
}
echo "
";
// 5. Revisar el .htaccess
echo "";
echo "
🔧 VERIFICACIÓN .HTACCESS...
";
if (file_exists('.htaccess')) {
echo "
✅ .htaccess existe en raíz
";
$htaccess_content = file_get_contents('.htaccess');
// Verificar reglas que pueden afectar a la API
if (strpos($htaccess_content, 'RewriteEngine On') !== false) {
echo "
✅ RewriteEngine habilitado
";
}
if (strpos($htaccess_content, 'api/') !== false) {
echo "
⚠️ Hay reglas específicas para api/
";
preg_match_all('/.*api.*/', $htaccess_content, $api_rules);
foreach ($api_rules[0] as $rule) {
echo "
📋 " . htmlspecialchars(trim($rule)) . "
";
}
}
} else {
echo "
❌ .htaccess no encontrado
";
}
// Verificar .htaccess en API
if (file_exists('api/.htaccess')) {
echo "
⚠️ .htaccess existe en api/
";
} else {
echo "
✅ No hay .htaccess específico en api/
";
}
echo "
";
// 6. Resumen y recomendaciones
echo "";
echo "
📊 DIAGNÓSTICO Y RECOMENDACIONES
";
echo "
PROBLEMA IDENTIFICADO:
";
echo "
Los archivos de la API están buscando 'config/config.php' desde su propia carpeta
";
echo "
Pero config.php está en '../config/config.php' desde la perspectiva de la API
";
echo "
SOLUCIONES:
";
echo "
1. Cambiar todas las rutas en api/ de 'config/config.php' a '../config/config.php'
";
echo "
2. O crear un archivo api/config.php que incluya '../config/config.php'
";
echo "
3. Verificar permisos de archivos
";
echo "
ARCHIVO CORRECTOR AUTOMÁTICO:
";
echo "
Necesitas ejecutar un script que corrija todas las rutas en los archivos API
";
echo "
";
echo "