我试图在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 …Run Code Online (Sandbox Code Playgroud)