我想在Symfony 3中创建一个包含多个文件(图像)上传的表单和简单的表单(我不使用symfony表单构建器),但我只获得一个文件(第一个文件) . 我正在使用POSTMAN通过post方法发送文件 .
public function testAction(Request $request)
{
$file = $request->files->get('images');
$ext = $file->guessExtension();
$file_name = time() . '.' . $ext;
$path_of_file = 'uploads/test';
$file->move($path_of_file, $file_name);
var_dump($file);
die();
}
1 回答
你没有提供足够的信息,但问题可能是你没有在Postman中将关键属性设置为像'images []'那样的数组 - 而是你的Symfony endpoints 将得到一个UploadedFile对象数组,其中包含所有需要的数据你的文件,你还需要将foreach放在你的代码中: