I am trying to import a CSV file into Symfony 2. I created a file form and now want to save it in my database.
Here is my handler file where I want to do .csv processing and save it:
public function process() { if ($this->request->getMethod() == 'POST') { $this->form->bindRequest($this->request); $tableau = array(); $i = 0; $c = 0; $num = 0; if (isset($_FILES['file'])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file,'r'); $row = 1; $handle = fopen("$file", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num =+ count($data); $row++; for ($c = $i; $c < $num; $c++) { $tableau[$c] = $data[$c]; $i++; } } } $tableau[$c+1] = $i; } return false; }
When I try to test it, the text appears on top of my page:
Array ([fichier] => Symfony \ Component \ HttpFoundation \ File \ UploadedFile Object ([test: Symfony \ Component \ HttpFoundation \ File \ UploadedFile: private] => [originalName: Symfony \ Component \ HttpFoundation \ File \ UploadedFile: private] => testcsv.csv [mimeType: Symfony \ Component \ HttpFoundation \ File \ UploadedFile: private] => text / csv [size: Symfony \ Component \ HttpFoundation \ File \ UploadedFile: private] => 491 [error: Symfony \ Component \ HttpFoundation \ File \ UploadedFile: private] => 0 [pathName: SplFileInfo: private] => / Applications / MAMP / tmp / php / phpSr5O5S [file_name: SplFileInfo: private] => phpSr5O5S))
I do not understand these things.
source share