如何在 Symfony 1.2 中上传文件而不使用特定表单
到目前为止,我还没有在 Symfony 中完成太多文件上传,我正在尝试弄清楚如何在 1.2+ 中执行此操作,
我可以将文件提交给操作并通过以下方式检索它们:
$files = $request->getFiles();
我如何获取然后保存文件到文件系统?除了旧的 1.0 折旧代码之外,我没有看到任何文档。
看起来这已经以某种方式转移到表单系统中,但我没有专门针对这个一次性页面,该页面除了上传一些文件之外什么也不做。
我怎样才能将这些文件保存到光盘上。
I haven't done much file uploading in Symfony to this point and I'm trying to figure out how to do it in 1.2+
I can get the files submitted to the action and retrieve them via:
$files = $request->getFiles();
How can I get then save the file to the file system? I don't see any documentation besides the old 1.0 depreciated code.
It looks like this has been moved somehow into the form system but I don't have a specific for for this one-off page that I have that does nothing but upload a few files.
How can I save these files to disc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您不希望使用 symfony 表单上传文件,那么以下编码也可以使用:
If you are not looking to upload the files using the symfony forms then the following coded will also work:
在操作内部,将参数绑定到表单后:
顺便说一句,您可以在相应的 Symfony Forms in Action 书中找到 Symfony 1.2 的文档: 第02章文件上传
ps:不要忘记手动添加
enctype="multipart/form-data" 到你的 html 表单!
Inside the action, after you bind the params to the form:
btw, you can find the documentation for Symfony 1.2 in the corresponding Symfony Forms in Action book: Chapter 02 file upload
ps : Don't forget to manually add the
enctype="multipart/form-data"
to your html form!谢谢你的朋友。
我找这个代码已经两天了。即使我正在尝试 symfony,我还是 php 新手。
我的 symfony 代码。
同样的方式使用
$filetype
来检查上传的文件类型。检查 php 文件参考。对于文件类型。享受..Thank you friend.
I'm looking for this code for 2 days. I'm new to php even i'm trying symfony.
My code for symfony.
same way use the
$filetype
to check the uploaded file type. Check php file reference. For file types. Enjoy..如果您仍然想知道为什么无法使用 $request->getFiles() 访问上传的文件,可能是因为您忘记添加
enctype="multipart/form-data"
。实际上,您应该有一个这样的表单:
并且您的操作应该执行这样的操作:
希望它有帮助!
If you're still looking why you can't access to the uploaded file using $request->getFiles(), it might be because you forgot to add
enctype="multipart/form-data"
.Actually, you should have a form like this:
And your action should do something like this:
Hope it helps !