Coldfusion 表单和使用 cffile 上传图像
我正在学习一些 Coldfusion,但我在为同事构建的这个基于小型表单的应用程序时遇到了麻烦。
这是第一页: http://pastebin.com/aLPYHPsF
如您所见,我想要什么要做的就是获取用户输入并将该输入输出到 html。文本内容工作正常,但我无法上传图像!我想要做的是让用户单击上传,获得确认,然后单击提交,然后将它们发送到生成的 html (cfm) 页面。页面上是他们上传的图像的调整大小版本。 请告诉我我做错了什么!现在,当单击“上传”时,表单就会转储。
I'm learning some Coldfusion, and I'm having trouble with this small form based application I'm building for a coworker.
Here is the first page: http://pastebin.com/aLPYHPsF
As you can see, what I want to do is get the user input and take that input and output it to html. The text stuff works fine, but I can't get the image to upload! What I want to do is have the user click upload, get a confirmation, then click submit and they are sent to the generated html (cfm) page. On the page is a resized version of the image they uploaded.
Please tell me what I'm doing wrong! Right now when "upload" is clicked, the form just dumps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您忘记将 enctype="multipart/form-data" 分配给您的第一个 cfform。我编辑了你的一些代码。一探究竟。
It's because of you forgot to assign enctype="multipart/form-data" to your first cfform. I've edited some of your coding. Check it out.
您可能需要考虑在图像上传部分使用
。基本上,您希望用于图像上传的表单位于
内,以便通过 ajax 提交表单。将图像表单操作发布到使用
的 PreviewImage.cfm,使用isImageFile()
验证它是否是图像文件,然后使用< ;cfimage>
调整其大小并显示缩略图(可以使用action="writetobrowser"
)。如果您不想编写额外的 JavaScript 代码,我想将上传的图像与父表单关联起来的最简单方法是将文件路径存储在会话中。You might want to look into using
<cfdiv>
for the image upload section. Basically you want the form for image uploading be inside the<cfdiv>
, so that the form is submitted through ajax. Have the image form action post to a previewImage.cfm that uses<cffileupload>
, validate withisImageFile()
if it is an image file, then use<cfimage>
to resize it and display a thumbnail (may useaction="writetobrowser"
). The easiest way to associate the uploaded image with the parent form would be storing the file path in Session I guess, if you don't want to code up extra Javascript.