【问题标题】:Script function for file upload in ColdFusion 9ColdFusion 9中文件上传的脚本函数
【发布时间】:2011-01-14 22:26:22
【问题描述】:

ColdFusion 9 中是否有等效于 cffile action="upload" 的 cfscript?翻阅文档,似乎没有。

[更新] 这是在 9.0.1 更新中添加的 http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSd160b5fdf5100e8f36f73035129d9e70a92-8000.html

【问题讨论】:

  • fileUpload(getTempDirectory(),"ImageFile","","makeUnique");

标签: coldfusion file-upload upload


【解决方案1】:

不确定何时添加,但 CF 确实支持在 CFSCRIPT 中上传文件。我已经使用 FileUpload() 有一段时间了。我已经检查过它不是我的 MVC 框架中的一个函数,并且 def 似乎是 CF 9.01 独有的。

但是,Builder 2 似乎不喜欢它,我也无法在 CF 9 Docs 上找到参考,但它确实有效,它是最新的 Adob​​e ColdFusion 9.01 的一部分,我还没有检查过 Ralio

使用示例:

fileUpload(getTempDirectory(),"ImageFile","","makeUnique");

【讨论】:

    【解决方案2】:

    您可以使用用户定义的函数轻松抽象它。

    <cffunction name="fileuploader">
        <cfargument name="formfield" required="yes" hint="form field that contains the uploaded file">
        <cfargument name="dest" required="yes" hint="folder to save file. relative to web root">
        <cfargument name="conflict" required="no" type="string" default="MakeUnique">
        <cfargument name="mimeTypesList" required="no" type="string" hint="mime types allowed to be uploaded" default="image/jpg,image/jpeg,image/gif,image/png,application/pdf,application/excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,image/pjpeg">
    
        <cffile action="upload" fileField="#arguments.formField#" destination="#arguments.dest#" accept="#arguments.mimeTypesList#" nameConflict="#arguments.conflict#">
    
        <cfreturn cffile>
    </cffunction>
    

    然后在cfscript中使用:

    <cfscript>
        // NOTE: because of how cffile works, put the form field with the file in quotes.
        result = fileUploader("FORM.myfield", myDestPath);
        WriteOutput(result.fileWasSaved);
    </cfscript>
    

    注意:如果 Adob​​e 将来确实包含此功能,我会非常小心如何重命名此功能。

    【讨论】:

    • 这正是我过去所做的,我只是希望我能在 9 内避免它。也许在 10 内。
    • 新增功能,见上面编辑问题中的链接
    【解决方案3】:

    没有,但它已被请求。

    【讨论】:

    • 奇怪的是上传没有包括在内,考虑到添加的文件功能的数量。
    猜你喜欢
    • 2013-07-07
    • 1970-01-01
    • 2014-05-02
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多