diff --git a/index.php b/index.php index 44c0365..36aa69c 100644 --- a/index.php +++ b/index.php @@ -1185,10 +1185,17 @@ function getPromotionalPrice($item) { $message = "Error: It looks like you uploaded an Excel (.xlsx) file. Please save it as CSV (UTF-8) and try again."; } else { $handle = fopen($tmpPath, "r"); - fgetcsv($handle); // Skip header + $firstLine = fgets($handle); + rewind($handle); + + $sep = ","; + if (strpos($firstLine, ";") !== false && strpos($firstLine, ",") === false) $sep = ";"; + elseif (strpos($firstLine, "\t") !== false) $sep = "\t"; + + fgetcsv($handle, 0, $sep); // Skip header $count = 0; $errors = 0; - while (($data = fgetcsv($handle)) !== FALSE) { - if (empty($data[1]) && empty($data[2])) continue; + while (($data = fgetcsv($handle, 0, $sep)) !== FALSE) { + if (empty($data[0]) && empty($data[1]) && empty($data[2])) continue; try { foreach ($data as &$val) { if ($val === null) continue; @@ -1203,7 +1210,7 @@ function getPromotionalPrice($item) { sale_price=VALUES(sale_price), purchase_price=VALUES(purchase_price)") ->execute([$data[0] ?? '', $data[1] ?? '', $data[2] ?? '', (float)($data[3] ?? 0), (float)($data[4] ?? 0)]); $count++; - } catch (Exception $e) { + } catch (Throwable $e) { $errors++; } }