Yii using uploaded file and rerender it


I’m new in Yii2. I have a homework from school, i need to upload an excel file, and then display some columns from that excel. I maked the upload button and the part who parse the file but i don’t know how to send selected file to the function who parse files and then to display parsed data in view.

Any ideas ?

Hi and welcome to the community @alexsultana!

There’s a nice section in the guide about how to upload files to the server: https://www.yiiframework.com/doc/guide/2.0/en/input-file-upload

Have a look, give it a try, and let us know if you need any help.

1 Like

Hello @machour
Thank you for your advice! I made the tutorial.
My problem is that i don’t need to save file. I need to select an excel file and just take the data inside that file. I can make a workaround, save that file, take data and after delete file that i saved.

I have 2 questions:
1)How can I, after I update the file and take the inside data, to display that data in the same page that i have the upload button ?
2) Can I delete an uploaded file ?

For parsing the excel file I used this:

$objPHPExcel = \PHPExcel_IOFactory::load($file);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
where $file is the full path to file.

Thank you!