Correzioni per l'esportazione dei CSV

This commit is contained in:
Dasc3er 2020-12-04 16:37:07 +01:00
parent 33fd4ba365
commit 634c88229f
5 changed files with 18 additions and 10 deletions

2
.gitignore vendored
View File

@ -82,6 +82,8 @@ files/*
!files/impianti/ !files/impianti/
files/impianti/* files/impianti/*
!files/impianti/componente.ini !files/impianti/componente.ini
!files/temp/
files/temp/*
tmp/ tmp/
config.inc.php config.inc.php
database.sql database.sql

0
files/temp/.gitkeep Normal file
View File

View File

@ -334,9 +334,13 @@ if (!function_exists('download')) {
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
$open = fopen($file, 'rb'); $open = fopen($file, 'rb');
fseek($open, 0, SEEK_END);
$size = ftell($open);
header('Content-Length: '.$size);
fseek($open, 0);
while (!feof($open)) { while (!feof($open)) {
echo fread($open, 1024 * 8); echo fread($open, 1024 * 8);
ob_flush(); ob_flush();
@ -544,12 +548,15 @@ if (!function_exists('temp_file')) {
$name = secure_random_string(); $name = secure_random_string();
} }
/*$file = DIRECTORY_SEPARATOR. // $base_directory = trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR);
trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR). $base_directory = implode(DIRECTORY_SEPARATOR, [
trim(base_dir(), DIRECTORY_SEPARATOR),
'files',
'temp',
]);
$file = trim($base_directory, DIRECTORY_SEPARATOR).
DIRECTORY_SEPARATOR. DIRECTORY_SEPARATOR.
ltrim($name, DIRECTORY_SEPARATOR);*/ ltrim($name, DIRECTORY_SEPARATOR);
$file = implode(DIRECTORY_SEPARATOR, [base_dir(), 'files', 'temp', ltrim($name, DIRECTORY_SEPARATOR)]);
file_put_contents($file, $content); file_put_contents($file, $content);

View File

@ -70,7 +70,7 @@ switch (post('op')) {
$exporter = new CSV($file); $exporter = new CSV($file);
// Esportazione dei record selezionati // Esportazione dei record selezionati
$anagrafiche = Anagrafica::whereIn('id', $id_records)->get(); $anagrafiche = Anagrafica::whereIn('idanagrafica', $id_records)->get();
$exporter->setRecords($anagrafiche); $exporter->setRecords($anagrafiche);
$count = $exporter->exportRecords(); $count = $exporter->exportRecords();

View File

@ -431,8 +431,7 @@ switch (post('op')) {
break; break;
case 'export-csv': case 'export-csv':
$file = temp_file().'.csv'; $file = temp_file();
$exporter = new CSV($file); $exporter = new CSV($file);
// Esportazione dei record selezionati // Esportazione dei record selezionati