Reputation: 35
I'm trying to retrieve the data from my csv file sent via the form but the result is null.
Form :
$form = $this->createFormBuilder()
->add('submitFile', FileType::class, array('label' => 'File to Submit'))
->add('add', SubmitType::class)->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$filename = $form['submitFile']->getData();
dump($filename); exit; // i have result of null here
$header = NULL;
$data = array();
$delimiter = ';';
if (($handle = fopen($filename, 'r')) !== FALSE) {
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
if(!$header) {
$header = $row;
} else {
$data[] = array_combine($header, $row);
}
}
fclose($handle);
}
return $data;
Am I doing something wrong?
Upvotes: 1
Views: 1546
Reputation: 2901
did you try to dump $form->getData()
?
and also check that you file does not exceed file maximum size defined in php.ini
Upvotes: 1