added photo functionality
This commit is contained in:
@@ -10,7 +10,7 @@ session_start();
|
||||
// Includi PHPSpreadsheet
|
||||
require_once '../../vendor/autoload.php';
|
||||
|
||||
$response = ['error' => '', 'rows' => [], 'columns' => [], 'template_id' => 0];
|
||||
$response = ['error' => '', 'rows' => [], 'columns' => [], 'template_id' => 0, 'filename' => ''];
|
||||
|
||||
try {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['excel_file'])) {
|
||||
@@ -22,7 +22,30 @@ try {
|
||||
$fileError = $file['error'];
|
||||
|
||||
if ($fileError === UPLOAD_ERR_OK) {
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file['tmp_name']);
|
||||
// Recupera l'ID dell'utente loggato (assumiamo sia disponibile in $iduserlogin)
|
||||
if (!isset($iduserlogin)) {
|
||||
$iduserlogin = 1; // Valore di default
|
||||
error_log("Warning: iduserlogin non definito, usando 1 come default");
|
||||
}
|
||||
|
||||
// Genera il nome del file rinominato
|
||||
$timestamp = date('YmdHis');
|
||||
$originalFilename = basename($file['name']);
|
||||
$newFilename = "{$iduserlogin}-{$timestamp}-{$originalFilename}";
|
||||
$importFolder = __DIR__ . '/imported_trf/';
|
||||
if (!file_exists($importFolder)) {
|
||||
mkdir($importFolder, 0777, true);
|
||||
}
|
||||
$destination = $importFolder . $newFilename;
|
||||
|
||||
// Sposta il file
|
||||
if (!move_uploaded_file($file['tmp_name'], $destination)) {
|
||||
throw new Exception("Errore durante lo spostamento del file in $destination");
|
||||
}
|
||||
error_log("File spostato con successo in: $destination");
|
||||
|
||||
// Carica il file rinominato con PHPSpreadsheet
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($destination);
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
$highestRow = $worksheet->getHighestRow();
|
||||
$highestColumn = $worksheet->getHighestColumn();
|
||||
@@ -72,6 +95,7 @@ try {
|
||||
$response['rows'] = $excelData;
|
||||
$response['columns'] = $headerRowData; // Usa gli header reali
|
||||
$response['template_id'] = $template_id;
|
||||
$response['filename'] = $newFilename; // Aggiungi il nome del file rinominato
|
||||
}
|
||||
} else {
|
||||
$response['error'] = "Errore nell'upload del file: Codice errore $fileError.";
|
||||
|
||||
Reference in New Issue
Block a user