Could not open /tmp/phpTIBSz5 for reading!
Hi @rap2hpoutre, great job with the package. I tried importing a CSV file through form upload but it is not read. I have tried every means of debugging. I came across a solution that suggested storage but I don't want to do that.
This is how I try to import: (new FastExcel())->import(request()->file('file'));
Hi @000kelvin thank you for your feedback!
I came across a solution that suggested storage but I don't want to do that
It may be the best solution though. Why would you not want to use storage? (see this post: https://github.com/rap2hpoutre/fast-excel/issues/18#issuecomment-384069693 for implementation)
You could also have a look at these issues:
- https://github.com/rap2hpoutre/fast-excel/issues/57
- https://github.com/rap2hpoutre/fast-excel/issues/53
Let me know if it fixes your problem.
I did end up using storage as the file input didn't work out.
Same issue with csv file only, xlsx file is working fine
The path is tmp
I tried the sample https://github.com/rap2hpoutre/fast-excel/blob/master/tests/test2.csv but it did not work either.
But file_get_contents is working fine.
If you don't want to store files, you can use it:
$filePath = $request->file('file')->path();
$newFilePath = $filePath . '.' . $request->file('file')->getClientOriginalExtension();
move_uploaded_file($filePath, $newFilePath);
FastExcel::import($newFilePath, function ($line) {
// do
});
it can only determine the extension, but, php tmp name does not contain extension. https://github.com/rap2hpoutre/fast-excel/blob/36e8bb704925f1074dc6b475082a52fd1a99e3d6/src/Importable.php#L90-L96
@rap2hpoutre, thank you for your work on this package which is super fast and light-weight.
Even i had encountered this same problem when using CSV files and after digging into the package implementation, we can get mime type of the temp file that is uploaded from a form and i tried this out in private function reader($path) to fix the problem.
if (Str::contains($path->getClientMimeType(), 'csv')) {
$options = new \OpenSpout\Reader\CSV\Options();
$this->setOptions($options);
$reader = new \OpenSpout\Reader\CSV\Reader($options);
} elseif (Str::contains($path->getClientMimeType(), 'opendocument.spreadsheet')) {
$options = new \OpenSpout\Reader\ODS\Options();
$this->setOptions($options);
$reader = new \OpenSpout\Reader\ODS\Reader($options);
} else {
$options = new \OpenSpout\Reader\XLSX\Options();
$this->setOptions($options);
$reader = new \OpenSpout\Reader\XLSX\Reader($options);
}