rap2hpoutre / fast-excel

🦉 Fast Excel import/export for Laravel
MIT License
2.09k stars 246 forks source link

feat: add 3rd parameter in import to define file extension (#1) #302

Closed lioneil closed 1 year ago

lioneil commented 1 year ago

This is a great package. Thanks.

Please consider reviewing this pull request.

Useful for directly importing from /tmp folder or from UploadedFile.

Sample usage:


...

$rows = with(new FastExcel)->import($request->file('file'), $cb = null, $fileExtension = 'csv');
$rows = with(new FastExcel)->import('/tmp/xHyuxLp', $cb = null, $fileExtension = 'ods');

or

$rows = with(new FastExcel)->import($request->file('file'), $cb = null); // which auto detects the file via UploadedFile::extension() method

This will solve #185

One of the proposed solution from that thread is to rename the file with its extension (e.g. mv /tmp/xyz /tmp/xyz.csv). This might not be ideal, as PHP will not delete/garbage collect the moved item from the /tmp file (at least on my tests in docker it didn't delete /tmp/randomhash.csv files).

Thanks.