代码之家  ›  专栏  ›  技术社区  ›  Ryan McIlmoyl

用于在ColdFusion 9中上载文件的脚本函数

  •  5
  • Ryan McIlmoyl  · 技术社区  · 16 年前

    在ColdFusion 9中是否有cfFile action=“upload”的cfscript等效项?看了看医生,好像没有。

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

    3 回复  |  直到 14 年前
        1
  •  10
  •   Dan Sorensen    16 年前

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

    <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>
    

    注意:如果Adobe包含了这个功能,我会非常小心地重命名这个功能。

        2
  •  3
  •   Prometheus    14 年前

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

    但是,builder 2似乎不喜欢它,也无法在CF 9文档中找到引用,但它确实有效,它是最新的Adobe ColdFusion 9.01的一部分,Ralio,我没有检查过

    使用实例:

    fileUpload(getTempDirectory(),"ImageFile","","makeUnique");
    
        3
  •  1
  •   Raymond Camden    16 年前

    没有,但已经请求了。