当我尝试在 Ubuntu 的服务器上使用 Maatwebsite 3.1 版本导入 excel 表时,出现此类错误。
Error:
Maatwebsite \ Excel \ Exceptions \ NoTypeDetectedException
No ReaderType or WriterType could be detected. Make sure you either pass a valid extension to the filename or pass an explicit type.
Controller
$path = $request->file('mcafile')->getRealPath();
$data = \Excel::import(new UsersImport,$path);
但是相同的导入 excel 代码在我的本地 Windows 机器上运行良好。 我上传的每个代码和文件都是相同的。但在本地和服务器中的工作方式不同。谁能帮忙。
最佳答案
所以问题出在 getRealPath() 上。 最初我试图通过,
$path = $request->file('mcafile')->getRealPath();
但现在我通过将它存储到临时文件并从那里检索路径并将其发送到函数来更改它。 像这样,
$path1 = $request->file('mcafile')->store('temp');
$path=storage_path('app').'/'.$path1;
$data = \Excel::import(new UsersImport,$path);
关于windows - Maatwebsite 导入在 ubuntu 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105889/