在对象中上传文件 [英] Upload File in Object

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

问题描述

我做错了什么?

fileUpload.cfm

<cfcomponent name="fileAttachment" hint="This is the File Attachment Object">

    <cffunction name="uploadFile" access="public" output="no" returntype="string">
        <cfargument name="fileToUpload" type="string" required="no">
        <cfargument name="pDsn" required="no" type="string">
        <cfset var cffile = "">
        <cffile action="upload" destination="D:\apache\htdocs\abc\uploads" filefield="#ARGUMENTS.fileToUpload#" nameconflict="makeunique">
        <cfreturn cffile.clientFile />
    </cffunction>

</cfcomponent>

test_fileUpload.cfm

<form action="fileUpload.cfm" enctype="multipart/form-data" method="post">
    <input type="file" name="fileToUpload"><br/>
    <input type="submit">
</form>


推荐答案

此行:

<cffile action="upload" destination="D:\apache\htdocs\abc\uploads" filefield="#ARGUMENTS.fileToUpload#" nameconflict="makeunique">

filefield属性想要表单字段的名称上传文件。你是在正确的轨道,但不幸的是,这不是#ARGUMENTS.fileToUpload#的价值,目前 - 根据你的构造,它持有一个引用

The filefield attribute wants the name of the form field that will hold the uploaded file. You're on the right track, but unfortunately, that's not what the value of #ARGUMENTS.fileToUpload# is, presently--based on your construction, it holds a reference to the actual file itself.

在您的表单中添加一个新的隐藏字段:

Add a new hidden field to your form:

<input type="hidden" name="nameOfField" value="fileToUpload">

然后,将 FORM.nameOfField uploadFile()方法作为第一个参数。 CFFILE将负责其余的工作。

Then, pass FORM.nameOfField to your uploadFile() method as the first parameter. CFFILE will take care of the rest.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆