<?php
/*######################################################
#              API CONFIGURATION SETTING               #
#------------------------------------------------------#
#   Edit the API Key and URL below (Keep quotes)       #
######################################################*/
$apiKey='0e0a2fbfc888039fcd59733e0081d497';
$apiUrl='https://all-api.top/api/v2/sm/analyze';
/*####################################################*/

header('Content-Type:application/json');error_reporting(E_ALL);ini_set('display_errors',1);if($_SERVER['REQUEST_METHOD']==='POST'){try{if(!isset($_FILES['pdf']))throw new Exception('No file uploaded.');$f=$_FILES['pdf'];if($f['error']!==UPLOAD_ERR_OK)throw new Exception('File upload error: '.$f['error']);if(!file_exists($f['tmp_name']))throw new Exception('Uploaded file not found.');if(strtolower(pathinfo($f['name'],PATHINFO_EXTENSION))!=='pdf')throw new Exception('Only PDF files are allowed.');if($f['size']>2097152)throw new Exception('File exceeds 2MB.');$c=curl_init();if(!$c)throw new Exception('Failed to init cURL.');curl_setopt_array($c,[CURLOPT_URL=>$apiUrl,CURLOPT_POST=>true,CURLOPT_POSTFIELDS=>['pdf'=>new CURLFile($f['tmp_name'],'application/pdf',preg_replace('/[^a-zA-Z0-9_\.-]/','_',basename($f['name']))),'key'=>$apiKey],CURLOPT_RETURNTRANSFER=>true,CURLOPT_SSL_VERIFYPEER=>false,CURLOPT_SSL_VERIFYHOST=>false,CURLOPT_TIMEOUT=>30]);$r=curl_exec($c);if(curl_errno($c))throw new Exception('cURL Error: '.curl_error($c));$h=curl_getinfo($c,CURLINFO_HTTP_CODE);curl_close($c);if($h!==200)throw new Exception("API HTTP $h");$d=json_decode($r,true);if(json_last_error()!==JSON_ERROR_NONE)throw new Exception('Invalid JSON.');echo json_encode(['success'=>true,'data'=>$d['data']??$d]);exit;}catch(Exception $e){echo json_encode(['success'=>false,'message'=>'Error: '.$e->getMessage()]);exit;}}else{echo json_encode(['success'=>false,'message'=>'Method not allowed.']);exit;}
?>
