'Laravel Excel::store file empty after stored
I uploaded this excel file: myExceldocument.xlsx
After uploading I want to store in a folder.
I used this method:
$uploadedFile = $request->file('files')[0]->getClientOriginalName(); //it worked
Excel::store(new DeductionsImport, $uploadedFile, 'documents');
'documents'
is related to filesystem.
The excel file is correctly filed in my folder called 'documents'.
The problem is when I open it, the excel file is empty! Do you know why ?
My goal is only upload an excel document and store in folder.
Solution 1:[1]
Excel::store
is for storing exports, not saving uploaded files.
If you are simply trying to save your myExceldocument.xlsx
to your documents folder, the request object has a simple method for it.
// Where 'files' is the name of the upload field in HTML.
$request->file('files')->store('documents');
Solution 2:[2]
Another example:
$fileNameToStore = $request->file('files')[0]
Storage::disk('documents')->put($fileNameToStore, fopen($file, 'r+'));
work but is not the best solution because folder is filed with '' :
$file->storeAs('',$file->getClientOriginalName(),'documents');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bobby W |
Solution 2 | General Grievance |