我是Coldfusion的新手,我很难弄清楚如何让用户以我的形式上传图片
目前,我能够找到以下代码,将在Coldfusion中上传图像:
<cfparam name="form.fileUpload" default="">
<cfif len(trim(form.fileUpload))>
<cffile action="upload"
fileField="fileUpload"
destination="C:\docs">
<p>Thankyou, your file has been uploaded.</p>
</cfif>
<form enctype="multipart/form-data" method="post">
<input type="file" name="fileUpload" /><br />
<input type="submit" value="Upload File" />
</form>
虽然它让我知道如何处理我的问题,但我仍然不确定以下内容:
我希望能够将上传的图像上传到电子邮件,而不是destination="C:\docs"
将文件存储在驱动器中。原因是,一旦用户完成并提交表单,将向发送请求的用户和将在创建卡中分配的用户发送电子邮件。
我怎样才能做到这一点?任何建议和例子将不胜感激
答案 0 :(得分:0)
将CFMAILPARAM
与remove="yes"
一起使用。您还可以在电子邮件中显示文件名。完整的例子:
<cfmail
to="the@recipient.com"
subject="#application.companyName# Contact Submission"
type="html"
from="#form.email#">
<!--- WAS A FILE UPLOADED? --->
<cfif isDefined("form.attachment") and form.attachment neq ''>
<!--- SAVE THE FILE --->
<cffile action="upload" fileField="attachment" destination="#expandPath('./')#" nameConflict="Overwrite">
<!--- ATTACH TO EMAIL, THEN DELETE IT --->
<cfmailparam
disposition = "attachment"
file = "#expandPath('./' & cffile.serverfile)#"
remove = 'yes'>
<!--- MAKE THE FILE NAME A FORM FIELD --->
<cfset form.attachment = cffile.serverfile>
</cfif>
<html>
<body>
<cfset form.URL = cgi.http_referrer>
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<th>Field</th>
<th>Value</th>
</tr>
<cfloop list="#form.fieldnames#" index="f">
<tr>
<td nowrap="nowrap" valign="top">#replace(f, '_', ' ', 'all')#</td>
<td>#form[f]#</td>
</tr>
</cfloop>
</table>
</body>
</html>
</cfmail>