true, 'prediction' => $ml_response['label'], 'confidence' => $ml_response['confidence'], 'filename' => htmlspecialchars($safeName) ]; } else { $response = ['success' => false, 'error' => 'ML script returned invalid data.']; } } else { $response = ['success' => false, 'error' => 'Failed to execute the ML model script. Check server logs for details.']; } } else { $response = ['success' => false, 'error' => 'Failed to save the uploaded file. Check directory permissions.']; } } else { // Handle various upload errors $uploadErrors = [ UPLOAD_ERR_INI_SIZE => 'File is too large (server limit).', UPLOAD_ERR_FORM_SIZE => 'File is too large (form limit).', UPLOAD_ERR_PARTIAL => 'File was only partially uploaded.', UPLOAD_ERR_NO_FILE => 'No file was uploaded.', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.', UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.', UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.', ]; $errorCode = $_FILES['mri_image']['error'] ?? UPLOAD_ERR_NO_FILE; $errorMsg = $uploadErrors[$errorCode] ?? 'An unknown upload error occurred.'; $response = ['success' => false, 'error' => $errorMsg]; } echo json_encode($response);