Rya*_*oyl 5 coldfusion upload file-upload
在ColdFusion 9中是否有cfscript等效于cffile action ="upload"?通过文档查看,似乎没有.
[更新]这是在9.0.1更新中添加的 http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSd160b5fdf5100e8f36f73035129d9e70a92-8000.html
Dan*_*sen 10
您可以使用用户定义的函数轻松地对其进行抽象.
<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>
Run Code Online (Sandbox Code Playgroud)
然后在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>
Run Code Online (Sandbox Code Playgroud)
注意:如果Adobe确实包含此功能,我将非常小心地重命名此功能.
归档时间: |
|
查看次数: |
4317 次 |
最近记录: |