Script function for file upload in ColdFusion 9

2019-02-22 23:13发布

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

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

3条回答
该账号已被封号
2楼-- · 2019-02-22 23:34

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>

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.

查看更多
孤傲高冷的网名
3楼-- · 2019-02-22 23:50

Not sure when this was added but CF does support file uploads in CFSCRIPT. I have been using FileUpload() for a little while. I have checked it is not a function in my MVC framework and def seems to be something unique to CF 9.01.

However, Builder 2 does not seem to like it nor can I find reference on CF 9 Docs but it does works and it is part the lasted Adobe ColdFusion 9.01, Ralio I have not checked tho

examples used:

fileUpload(getTempDirectory(),"ImageFile","","makeUnique");
查看更多
贪生不怕死
4楼-- · 2019-02-22 23:54

Nope, but it has been requested.

查看更多
登录 后发表回答