我正在尝试在 Symfony 2 中导入一个 .csv 文件。我已经创建了一个文件表单,现在我想将它保存在我的数据库中。
这是我的处理程序文件,我想在其中进行 .csv 处理并将其持久化:
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;
/*
if ($this->form->isValid())
{
print_r($this->form->getData());
$this->onSuccess($this->form->getData());
return true;
}
*/
}
return false;
}
当我尝试对其进行测试时,我的页面顶部会出现一些文本:
数组 ( [fichier] => Symfony\Component\HttpFoundation\File\UploadedFile 对象 ( [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 [大小:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 491 [错误:Symfony\Component\ HttpFoundation\File\UploadedFile:private] => 0 [pathName:SplFileInfo:private] => /Applications/MAMP/tmp/php/phpSr5O5S [fileName:SplFileInfo:private] => phpSr5O5S ) )
我不明白那些事。