From 5ae47361f8a80a6ab51ade511a9117fdf436977a Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 16 Jan 2025 13:09:32 +0000 Subject: [PATCH] fix: excel file handling when there's CSV data within the xlsx closes #196 --- class/Upload/UploadRepository.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/class/Upload/UploadRepository.php b/class/Upload/UploadRepository.php index 897637f..566e2ec 100644 --- a/class/Upload/UploadRepository.php +++ b/class/Upload/UploadRepository.php @@ -48,9 +48,11 @@ public function create(User $user, FileUpload...$uploadList):array { $extension = pathinfo($targetPath, PATHINFO_EXTENSION); if($this->isCsv($targetPath) && $extension !== "csv") { rename($targetPath, "$targetPath.csv"); + $targetPath = "$targetPath.csv"; } elseif($this->isTsv($targetPath) && $extension !== "tsv") { rename($targetPath, "$targetPath.tsv"); + $targetPath = "$targetPath.tsv"; } Log::debug("Detected upload type: $uploadType"); @@ -200,6 +202,11 @@ private function detectUploadType(string $uploadedFilePath):string { } private function isCsv(string $filePath, string $separator = ","):bool { + $extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); + if($extension === "xlsx") { + return false; + } + $fh = fopen($filePath, "r"); $firstLine = fgetcsv($fh, separator: $separator); $secondLine = fgetcsv($fh, separator: $separator);