Zend Form File,如何向用户指示文件之前已上传?
我有一个 zend 表单,可以让用户填写对象的属性。例如,音乐艺术家。该表单包含有关艺术家的基本信息,例如姓名、电话号码、地址等,但它还有一个文件上传字段。如果用户上传文件,则该文件与该对象的实例一起存储在数据库中(本质上是一行),如果用户想要编辑该特定实例,则表单将重新填充对象信息。但是,该表单不会重新填充文件上传信息,因为它不会重新上传它。
我如何向用户发出文件已上传的信号,指示它是哪个文件,甚至可能链接到它?类似于填充表单元素的东西是首选。理想情况下,我希望能够为用户提供上传之前上传的文件的能力,因此文件上传元素应该保留。有什么想法吗?非常感谢您的阅读。
干杯, 陈乔恩
I have a zend form that lets the user fill out attributes of an object. For example, a music artist. The form has basic information about the artist, things like name, phone number, address, and what not, but it also has a file upload field. If the user uploads a file, its stored with this instance of the object in the database (essentially a row), if the user ever wants to edit this particular instance, the form is repopulated with the objects information. However the form does not repopulate the file upload information because its not going to reupload it.
How can I signal to the user that a file was already uploaded, indicate which file it was, and possibly even link to it? something similar to populating the form elements is preferred. I'd ideally like to be able to offer the user the ability to upload over the previously uploaded file, so the file upload element should stay. Any idea? Thanks a lot for reading.
Cheers,
Joe Chin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现实现此功能的最快方法是将 Chelmertz 的答案 与 此线程。
我没有定义装饰器来显示先前上传的文件,而是将链接放置在元素的描述中,然后将其转储到视图脚本中。
最终的解决方案如下所示:
Zend Form File:
查看处理文件详细信息和表单元素的脚本:
最后在控制器中我有:
这应该给你看起来像这样的东西:
The fastest way I found to get this implemented was to combine the answer from Chelmertz with this thread.
Instead of defining a decorator to show the previously uploaded file, I am placing the link in the description for the element and then I am dumping it into a view script.
The final solution looks like this:
Zend Form File:
View script to handle file details and form element:
Lastly in the controller I have:
This should give you something that looks like:
我会打印出之前上传的文件。
为了实现这一点,您可以使用表单装饰器。这是一个需要在考虑到安全性的情况下进行修改和重构的草图,但它确实会打印出图像标签。(如果您想显示文件列表,可以在结束。)
您不应该不填充文件元素,因为您不希望它一遍又一遍地上传相同的文件。
如果文件是 mp3 左右:遵循相同的例程,但使用如下输出:
将“歌曲”注入到表单的构造函数中。
I would print out the previously uploaded file.
To accomplish this, you could use a form decorator. This is a sketch that needs to be modified and refactored with security in mind, but it does print out an image-tag. (If you'd rather display a list of files, there's a hint in the end.)
You should not populate the file-element since it you don't want it to upload the same file over and over and over again.
If the file(s) a mp3 or so: follow the same routine but use an output like:
Inject the "songs" to the form's constructor.