CFfile -- 值未设置为查询的数据

发布于 2024-10-11 05:27:11 字数 1906 浏览 3 评论 0 原文

我有这个添加用户表单,它还可以通过查询数据并设置 value="#query.xvalue#" 来兼作编辑用户表单。如果用户存在(例如,您正在编辑用户,它会从数据库加载用户数据。在 字段上执行此操作时,它不会加载数据,那么当插入将用空白字符串覆盖数据库值(如果用户不输入新文件),

代码:

表单:

<br/>Digital Copy<br/>
<!--- If null, set a default if not, set the default to database default --->
<cfif len(Trim(certificationsList.cprAdultImage)) EQ 0>
 <cfinput type="file" required="no" name="cprAdultImage" value="" >
 <cfelse>
    File Exists: <cfoutput><a href="#certificationsList.cprAdultImage#">View File</a></cfoutput>
    <cfinput type="file" required="no" name="cprAdultImage"  value="#certificationsList.cprAdultImage#">
</cfif>        

表单处理器:

<!--- Has a file been specificed? ---> 
<cfif not len(Trim(form.cprAdultImage)) EQ 0>
    <cffile action="upload" filefield="cprAdultImage" destination="#destination#" nameConflict="makeUnique">
    <cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
<cfelse>
    <cfinvokeargument name="cprAdultImage" value="">
</cfif>

CFC

ARGS:

<cfargument name="cprAdultExp" required="NO">
<cfargument name="cprAdultCompany" type="string" required="no">
<cfargument name="cprAdultImage" type="string" required="no">
<cfargument name="cprAdultOnFile" type="boolean" required="no">   

查询:

UPDATE mod_StudentCertifications
SET 
cprAdultExp='#DateFormat(ARGUMENTS.cprAdultExp, "mm/dd/yyyy")#',
cprAdultCompany='#Trim(ARGUMENTS.cprAdultCompany)#',
cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
cprAdultOnFile='#Trim(ARGUMENTS.cprAdultOnFile)#'

INSERT INTO 
mod_StudentCertifications(
cprAdultExp,
cprAdultcompany,
cprAdultImage,
cprAdultOnFile

I have this add user form, it also doubles as a edit user form by querying the data and setting the value="#query.xvalue#". If the user exists (eg, you're editing a user, it loads in the users data from the database. When doing this on the <cffile field it does not load in the data, then when the insert goes to insert data it overrights the database values with a blank string (If a user does not input a new file). How do I avoid this?

Code:

Form:

<br/>Digital Copy<br/>
<!--- If null, set a default if not, set the default to database default --->
<cfif len(Trim(certificationsList.cprAdultImage)) EQ 0>
 <cfinput type="file" required="no" name="cprAdultImage" value="" >
 <cfelse>
    File Exists: <cfoutput><a href="#certificationsList.cprAdultImage#">View File</a></cfoutput>
    <cfinput type="file" required="no" name="cprAdultImage"  value="#certificationsList.cprAdultImage#">
</cfif>        

Form Processor:

<!--- Has a file been specificed? ---> 
<cfif not len(Trim(form.cprAdultImage)) EQ 0>
    <cffile action="upload" filefield="cprAdultImage" destination="#destination#" nameConflict="makeUnique">
    <cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
<cfelse>
    <cfinvokeargument name="cprAdultImage" value="">
</cfif>

CFC

ARGS:

<cfargument name="cprAdultExp" required="NO">
<cfargument name="cprAdultCompany" type="string" required="no">
<cfargument name="cprAdultImage" type="string" required="no">
<cfargument name="cprAdultOnFile" type="boolean" required="no">   

Query:

UPDATE mod_StudentCertifications
SET 
cprAdultExp='#DateFormat(ARGUMENTS.cprAdultExp, "mm/dd/yyyy")#',
cprAdultCompany='#Trim(ARGUMENTS.cprAdultCompany)#',
cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
cprAdultOnFile='#Trim(ARGUMENTS.cprAdultOnFile)#'

INSERT INTO 
mod_StudentCertifications(
cprAdultExp,
cprAdultcompany,
cprAdultImage,
cprAdultOnFile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め七分饶幸 2024-10-18 05:27:11

<如果不是
len(Trim(form.cprAdultImage)) EQ 0>

这实际上是在做与你想要的相反的事情。我相信你想说的是:

<!--- if the length is greater than 0, assume a file was uploaded --->
<cfif len(Trim(form.cprAdultImage)) GT 0>
     file is not empty. do the upload ...
     <cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
<cfelse>
    <cfinvokeargument name="cprAdultImage" value="">
</cfif>

编辑
顺便说一句,..由于所有参数都是可选的,因此代码感觉有点尴尬。

,

您无法真正预设文件控制“值”(浏览器安全限制)。由于用户在这两种情况下都可以上传文件,因此只需提供输入并仅在存在先前图像时才显示“查看”链接。

<cfif len(Trim(certificationsList.cprAdultImage))>
    File Exists: 
    <cfoutput><a href="#certificationsList.cprAdultImage#">View File</a></cfoutput>
</cfif>        
<cfinput type="file" required="no" name="cprAdultImage">

cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',

UPDATE 逻辑看起来也有点不对劲。如果未提供文件,您最终将用空字符串覆盖现有图像。为了避免这种情况,仅在提供了新文件(即非空)时才更新该字段。

表单处理:

<cfif len(Trim(form.cprAdultImage)) GT 0>
    <cffile action="upload" filefield="cprAdultImage" destination="#destination#" nameConflict="makeUnique">
    <cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
</cfif>

CFC ARGS:

<!--- if values are always used in queries, should be required=true --->
<cfargument name="cprAdultExp" required="yes">
<cfargument name="cprAdultCompany" type="string" required="yes">
<cfargument name="cprAdultOnFile" type="boolean" required="yes">   
<cfargument name="cprAdultImage" type="string" default="">

查询

UPDATE mod_StudentCertifications
SET 
cprAdultExp='#DateFormat(ARGUMENTS.cprAdultExp, "mm/dd/yyyy")#',
cprAdultCompany='#Trim(ARGUMENTS.cprAdultCompany)#',
<!--- only overwrite the value if a new file was supplied --->
<cfif len(trim(ARGUMENTS.cprAdultImage))>
   cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
</cfif>
cprAdultOnFile='#Trim(ARGUMENTS.cprAdultOnFile)#'
WHERE ....

并且不要忘记清理。删除所有旧文件...

<cfif not
len(Trim(form.cprAdultImage)) EQ 0>

That is actually doing the reverse of what you want. I believe what you are trying to say is:

<!--- if the length is greater than 0, assume a file was uploaded --->
<cfif len(Trim(form.cprAdultImage)) GT 0>
     file is not empty. do the upload ...
     <cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
<cfelse>
    <cfinvokeargument name="cprAdultImage" value="">
</cfif>

Edit
As an aside, .. since all of your arguments are optional, the code feels a bit awkward.

<cfinput type="file" required="no" name="cprAdultImage" value="#certificationsList.cprAdultImage#">,

You cannot really preset the file control "value" (browser security restrictions). Since a user can upload a file in both cases, just provide an input and display the "view" link only if a previous image exists.

<cfif len(Trim(certificationsList.cprAdultImage))>
    File Exists: 
    <cfoutput><a href="#certificationsList.cprAdultImage#">View File</a></cfoutput>
</cfif>        
<cfinput type="file" required="no" name="cprAdultImage">

cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',

The UPDATE logic looks a bit off as well. If a file was not supplied, you will end up overwriting the existing image with an empty string. To avoid that, only update that field if a new file was supplied (ie non-empty)

Form processing:

<cfif len(Trim(form.cprAdultImage)) GT 0>
    <cffile action="upload" filefield="cprAdultImage" destination="#destination#" nameConflict="makeUnique">
    <cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
</cfif>

CFC ARGS:

<!--- if values are always used in queries, should be required=true --->
<cfargument name="cprAdultExp" required="yes">
<cfargument name="cprAdultCompany" type="string" required="yes">
<cfargument name="cprAdultOnFile" type="boolean" required="yes">   
<cfargument name="cprAdultImage" type="string" default="">

Query

UPDATE mod_StudentCertifications
SET 
cprAdultExp='#DateFormat(ARGUMENTS.cprAdultExp, "mm/dd/yyyy")#',
cprAdultCompany='#Trim(ARGUMENTS.cprAdultCompany)#',
<!--- only overwrite the value if a new file was supplied --->
<cfif len(trim(ARGUMENTS.cprAdultImage))>
   cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
</cfif>
cprAdultOnFile='#Trim(ARGUMENTS.cprAdultOnFile)#'
WHERE ....

And do not forget cleanup. Remove any old files...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文