mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 04:14:33 -04:00
Fixes for csv file encodings
This commit is contained in:
parent
ec1b942145
commit
8a4da65b6b
@ -81,7 +81,8 @@ class ImportController extends Controller
|
|||||||
/** @var UploadedFile $file */
|
/** @var UploadedFile $file */
|
||||||
foreach ($request->files->get('files') as $entityType => $file) {
|
foreach ($request->files->get('files') as $entityType => $file) {
|
||||||
$contents = file_get_contents($file->getPathname());
|
$contents = file_get_contents($file->getPathname());
|
||||||
// $contents = mb_convert_encoding($contents, 'UTF-16LE', 'UTF-8');
|
|
||||||
|
$contents = $this->convertEncoding($contents);
|
||||||
|
|
||||||
// Store the csv in cache with an expiry of 10 minutes
|
// Store the csv in cache with an expiry of 10 minutes
|
||||||
Cache::put($hash.'-'.$entityType, base64_encode($contents), 600);
|
Cache::put($hash.'-'.$entityType, base64_encode($contents), 600);
|
||||||
@ -97,11 +98,21 @@ class ImportController extends Controller
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
|
||||||
|
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function convertEncoding($data)
|
||||||
|
{
|
||||||
|
|
||||||
|
$enc = mb_detect_encoding($data, mb_list_encodings(), true);
|
||||||
|
|
||||||
|
if($enc !== false) {
|
||||||
|
$data = mb_convert_encoding($data, "UTF-8", $enc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
public function import(ImportRequest $request)
|
public function import(ImportRequest $request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
@ -102,6 +102,8 @@ class BaseImport
|
|||||||
}
|
}
|
||||||
|
|
||||||
$csv = base64_decode($base64_encoded_csv);
|
$csv = base64_decode($base64_encoded_csv);
|
||||||
|
$csv = mb_convert_encoding($csv, 'UTF-8', 'UTF-8');
|
||||||
|
nlog($csv);
|
||||||
$csv = Reader::createFromString($csv);
|
$csv = Reader::createFromString($csv);
|
||||||
$csvdelimiter = self::detectDelimiter($csv);
|
$csvdelimiter = self::detectDelimiter($csv);
|
||||||
|
|
||||||
@ -765,8 +767,7 @@ class BaseImport
|
|||||||
{
|
{
|
||||||
$keys = array_shift($data);
|
$keys = array_shift($data);
|
||||||
ksort($keys);
|
ksort($keys);
|
||||||
// nlog($data);
|
|
||||||
// nlog($keys);
|
|
||||||
return array_map(function ($values) use ($keys) {
|
return array_map(function ($values) use ($keys) {
|
||||||
return array_combine($keys, $values);
|
return array_combine($keys, $values);
|
||||||
}, $data);
|
}, $data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user