尝试使用Silex/Symfony2从请求检索文件
我正在检索已发布的文件,其中包含:尝试使用Silex/Symfony2从请求检索文件,symfony,silex,bolt-cms,Symfony,Silex,Bolt Cms,我正在检索已发布的文件,其中包含: $this->app->post(Extension::API_PREFIX . "profile/picture", array($this, 'post_profile_pic')) ->bind('post_profile_pic'); public function post_profile_pic(Request $request) { $response = $this->app->json(ar
$this->app->post(Extension::API_PREFIX . "profile/picture", array($this, 'post_profile_pic'))
->bind('post_profile_pic');
public function post_profile_pic(Request $request) {
$response = $this->app->json(array(
'file' => $request
));
return $response;
}
我正在使用Postman上载文件(请参阅),但请求为空:
{
"file": {
"attributes": { },
"request": { },
"query": { },
"server": { },
"files": { },
"cookies": { },
"headers": { }
}
}
但它显然知道那里应该有一个文件。那么如何访问该文件呢?在PHP中上载的文件不是通过$\u POST发送的,而是在一个名为$\u files()的单独变量中发送的-因此在您的例子中,您应该查看
$this->app->files
如果使用symfony的默认表单组件,文档位于
在simpleforms模块中,通过以下行检索文件
$files = $this->app['request']->files->get($form->getName());
使用螺栓、Silex和Symfony组件提供的基本结构。
(另请参见)它可能根本无法序列化(IIRC UploadedFile就是这样)。如果执行
$request->files->count()
,会发生什么情况?