【问题标题】:How to store an image file after uploading the image file in ColdFusion在 ColdFusion 中上传图像文件后如何存储图像文件
【发布时间】:2018-02-27 23:13:32
【问题描述】:

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

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

【问题讨论】:

  • 您是否尝试将上传的图片附加到电子邮件中?
  • 我认为上传的数据是流式传输的,因此需要写入目的地。如果您希望数据不稳定,可以使用in-memory disk。但是为什么你需要一个变量呢?
  • @Alex:我不需要,但我不确定如何处理它,这就是我说变量的原因。
  • @RobertoFlores Check this out. 这看起来像你的场景。
  • 我还强烈警告不要允许将未经检查的文件保存到服务器上的驱动器中,即使它只是临时的。

标签: coldfusion cffile


【解决方案1】:

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>

【讨论】:

    猜你喜欢
    • 2016-12-30
    • 2020-07-10
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多