9中文件上传的脚本函数

9中文件上传的脚本函数

本文介绍了在ColdFusion 9中文件上传的脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ColdFusion 9中有一个cfscript等同于cffile action =upload吗?查看文档,似乎没有。

Is there a a cfscript equivalent for cffile action="upload" in ColdFusion 9? Looking through the docs, there doesn't seem to be.

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

[Update] This was added in the 9.0.1 updatehttp://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSd160b5fdf5100e8f36f73035129d9e70a92-8000.html

推荐答案

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

You can easily abstract it with a user defined function.

<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中使用它:

And then use it in 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>

注意:我会非常小心如何重命名此函数,道路。

Note: I would be very careful how you rename this function in case Adobe does include this functionality down the road.

这篇关于在ColdFusion 9中文件上传的脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 22:46