如何在ColdFusion中上传图像文件后存储图像文件

How to store an image file after uploading the image file in ColdFusion

我是 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" 将文件存储在驱动器上。原因是一旦用户完成并提交表单,将向提交请求的用户和将被分配创建卡片的用户发送一封电子邮件。

我怎样才能做到这一点?任何建议和示例将不胜感激

CFMAILPARAMremove="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>