使用 mysql 数据库中的文件名填充表单
我创建了一系列表单,供用户在数据库中添加和编辑记录。该数据库包括音频和图像文件名(实际文件在提交时移动到文件夹中)。
我的问题是我无法在编辑表单上显示文件名。这意味着除非用户再次上传文件,否则这些字段在数据库中将被清空!我知道“type='file'”不采用“value”属性。我可以通过简单地在文本区域中显示 php 变量来解决这个问题。我尝试使用文件名,它们确实显示,但在输入框之外,这意味着......见上文,数据库内的空白字段。
这是我正在使用的代码:
<li>
<label for=se_ogg">Sound excerpt (upload .ogg file)</label>
<input id="se_ogg" type = "file"
name = "se_ogg">' . $row['se_ogg'] . '</input>
</li>
有什么想法吗?这可以做到吗?
I've created a series of forms for users to add and edit records in a database. The database includes audio and image file names (the actual files are moved to folders on submit).
My problem is that I can't get the file names to display on the edit forms. Which means that unless the user uploads the files again, those fields are blanked in the database! I understand the "type='file'" does not take a "value" attribute. I was able to get around that in my textareas by simply displaying the php variable in the textarea. I tried that with file names, and they do display, but outside of the input box, which means... see above, blanked fields within the database.
Here's the code I'm using:
<li>
<label for=se_ogg">Sound excerpt (upload .ogg file)</label>
<input id="se_ogg" type = "file"
name = "se_ogg">' . $row['se_ogg'] . '</input>
</li>
Any ideas? Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出于安全原因,文件输入字段不允许您定义值,否则您可以隐藏文件字段并使用它从毫无戒心的人的计算机中获取文件。如果您只想显示刚刚上传的文件的文件名,只需将其显示为格式化文本即可。
The file input field doesn't allow you to define a value for security reasons otherwise you could hide a file field and use it to grab files from unsuspecting peoples computers. If you just want to display the filename of the file just uploaded just display it as formatted text.