forked from SimonezYT/fantacalcio-4h
40 lines
945 B
PHP
Executable File
40 lines
945 B
PHP
Executable File
<?php
|
|
require 'conversioni.php';
|
|
|
|
if (!isset($_GET['type'])) {
|
|
die('Tipo di esportazione non specificato.');
|
|
}
|
|
|
|
$type = $_GET['type'];
|
|
$sourceFile = '';
|
|
$outputFilename = '';
|
|
$exportFunction = '';
|
|
|
|
if ($type === 'giocatori') {
|
|
$sourceFile = 'giocatori.json';
|
|
$outputFilename = 'giocatori.csv';
|
|
$exportFunction = 'esportaGiocatori';
|
|
} elseif ($type === 'voti') {
|
|
$sourceFile = 'voti.json';
|
|
$outputFilename = 'voti.csv';
|
|
$exportFunction = 'esportaVoti';
|
|
} else {
|
|
die('Tipo di esportazione non valido.');
|
|
}
|
|
|
|
if (!file_exists($sourceFile)) {
|
|
die("File di origine non trovato: $sourceFile");
|
|
}
|
|
|
|
$jsonContent = file_get_contents($sourceFile);
|
|
$csvContent = $exportFunction($jsonContent);
|
|
|
|
header('Content-Type: text/csv; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename="' . $outputFilename . '"');
|
|
|
|
// Pulisce il buffer di output prima di inviare il file
|
|
ob_end_clean();
|
|
|
|
echo $csvContent;
|
|
exit;
|