Level 53
Try a package for that. A quick Google search will bring up a few. Reading a csv is easy but xslx is not. excel_reader2.php
I need to upload .xlsx file to database . I have 3 column in db value,pin_num,password_num
my code is like this
public function import(Request $request)
{
if($request->hasFile('file'))
{
$files = $request->file('file');
$file = fopen($files, "r");
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
$excel = new Excel;
$excel->value = $emapData[0];
$excel->pin_num = $emapData[1];
$excel->password_num = $emapData[2];
$excel->save();
}
}
return Redirect::to('dashboard/file/view');
This upload .csvfile successfullly but it gives error on uploading.xlsx file
Error is like this
Undefined offset: 1
in AdminController.php line 36
at HandleExceptions->handleError('8', 'Undefined offset: 1', '/var/www/html/project/app/Http/Controllers/Backend/Admin/AdminController.php', '36', array('request' => object(Request), 'files' => object(UploadedFile), 'file' => resource, 'emapData' => array('PK!q9+p��[Content_Types].xml ��(�̔MN�0��H�!�%n��j�?K��ؓƪc[���g��'), 'excel' => object(Excel))) in AdminController.php line 36
How to upload xlsx file?How to modify this code?
Please or to participate in this conversation.