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

用于在ColdFusion 9中上载文件的脚本函数,coldfusion,file-upload,upload,Coldfusion,File Upload,Upload,ColdFusion 9中是否有cffile action=“upload”的cfscript等价物?翻看这些文件,似乎没有 [更新]这是在9.0.1更新中添加的 没有,但它已被请求。您可以使用用户定义的函数轻松地对其进行抽象 <cffunction name="fileuploader"> <cfargument name="formfield" required="yes" hint="form field that contains the uploaded fi

ColdFusion 9中是否有cffile action=“upload”的cfscript等价物?翻看这些文件,似乎没有

[更新]这是在9.0.1更新中添加的

没有,但它已被请求。

您可以使用用户定义的函数轻松地对其进行抽象

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

//注意:由于cffile的工作方式,请将表单字段和文件一起放在引号中。
结果=文件上传器(“FORM.myfield”,myDestPath);
WriteOutput(result.filewasaved);

注意:我会非常小心如何重命名此功能,以防Adobe在将来包含此功能。

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

然而,Builder2似乎不喜欢它,我也无法在CF 9文档中找到参考,但它确实有效,并且它是最新的Adobe ColdFusion 9.01的一部分,我没有检查

使用的示例:

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

这正是我过去所做的,我只是希望我能在9月份避免它。可能在10中添加了新函数,请参见上面编辑的问题中的链接。考虑到添加的文件函数的数量,它的奇数上载未包括在内。fileUpload(getTempDirectory(),“ImageFile”,“makeUnique”);