mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for string delimiters
This commit is contained in:
parent
67c34f80a9
commit
84885837ab
@ -170,20 +170,27 @@ class ImportController extends Controller
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function detectDelimiter($csvfile)
|
||||
/**
|
||||
* Returns the best delimiter
|
||||
*
|
||||
* @param string $csvfile
|
||||
* @return string
|
||||
*/
|
||||
public function detectDelimiter($csvfile): string
|
||||
{
|
||||
$delimiters = [',', '.', ';'];
|
||||
$bestDelimiter = ' ';
|
||||
$count = 0;
|
||||
|
||||
foreach ($delimiters as $delimiter) {
|
||||
|
||||
|
||||
if (substr_count(strstr($csvfile, "\n", true), $delimiter) >= $count) {
|
||||
$count = substr_count($csvfile, $delimiter);
|
||||
$bestDelimiter = $delimiter;
|
||||
$count = substr_count(strstr($csvfile, "\n", true), $delimiter);
|
||||
$bestDelimiter = $delimiter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $bestDelimiter;
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,10 @@ class PreImportRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'files.*' => 'file|mimes:csv,txt',
|
||||
'files.*' => 'file|mimetypes:text/csv,text/plain,application/octet-stream',
|
||||
'files' => 'required|array|min:1|max:6',
|
||||
'import_type' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user