我有一个页面,用户可以在其中更新包含 4 个图像和其他一些字段的页面。已经为每个文件输入上传了一张图片,当他们上传新图片时,我想拍摄新图片,然后上传它,如果上传成功,请删除旧图片。但是我收到了这个错误。
File /var/www/mywebsite.com/Pics/Sunset3.jpg specified in action delete does not exist.
根据我的 ftp,这些文件确实存在于该目录中。这些文件甚至作为表单的一部分显示在页面上,以供用户参考已经存在的图像。我听说无法在同一页面上处理文件上传,您必须使用辅助文件,但这些图像是在上次访问该页面时上传的,因此它们不会在同一页面上上传和处理页。
这是我的代码。变量 tableName 是正确的,它是在代码前面定义的,加上数据库在上传尝试后反映了正确的值,它只是在删除时中断。
<cfquery name="getPreviousImage" datasource="#Application.datasourceName#">
SELECT
image1, image2, image3, image4
FROM
#tableName#
WHERE
RecordID = '#form.ID#'
</cfquery>
<cfset oldImage1 = getPreviousImage.image1>
<cfset oldImage2 = getPreviousImage.image2>
<cfset oldImage3 = getPreviousImage.image3>
<cfset oldImage4 = getPreviousImage.image4>
<cfset image1 = getPreviousImage.image1>
<cfset image2 = getPreviousImage.image2>
<cfset image3 = getPreviousImage.image3>
<cfset image4 = getPreviousImage.image4>
<cfif #form.image1# NEQ "">
<cffile action="upload" destination="#Application.filePath#Pics/" filefield="image1" nameconflict="makeunique">
<cfif isDefined ("cffile.serverFile")>
<cfset image1Place = #cffile.serverFile#>
</cfif>
<cfif #getPreviousImage.image1# NEQ "" AND #image1Place# NEQ "">
<cffile action="delete" file="#Application.filePath#Pics/#oldImage1#">
</cfif>
</cfif>
<cfif #form.image2# NEQ "">
<cffile action="upload" destination="#Application.filePath#Pics/" filefield="image2" nameconflict="makeunique">
<cfif isDefined ("cffile.serverFile")>
<cfset image2Place = #cffile.serverFile#>
</cfif>
<cfif #getPreviousImage.image2# NEQ "" AND #image2Place# NEQ "">
<cffile action="delete" file="#Application.filePath#Pics/#oldImage2#">
</cfif>
</cfif>
<cfif #form.image3# NEQ "">
<cffile action="upload" destination="#Application.filePath#Pics/" filefield="image3" nameconflict="makeunique">
<cfif isDefined ("cffile.serverFile")>
<cfset image3Place = #cffile.serverFile#>
</cfif>
<cfif #getPreviousImage.image3# NEQ "" AND #image3Place# NEQ "">
<cffile action="delete" file="#Application.filePath#Pics/#oldImage3#">
</cfif>
</cfif>
<cfif #form.image4# NEQ "">
<cffile action="upload" destination="#Application.filePath#Pics/" filefield="image4" nameconflict="makeunique">
<cfif isDefined ("cffile.serverFile")>
<cfset image4Place = #cffile.serverFile#>
</cfif>
<cfif #getPreviousImage.image4# NEQ "" AND #image4Place# NEQ "">
<cffile action="delete" file="#Application.filePath#Pics/#oldImage4#">
</cfif>
</cfif>
<cfquery name="UpdateInfo" datasource="#Application.datasourceName#">
UPDATE
#tableName#
SET
title = <cfqueryparam value="#form.title#" cfsqltype="CF_SQL_VARCHAR" maxlength="250">,
<cfif #image1Place# NEQ "">
image1 = <cfqueryparam value="#image1Place#" cfsqltype="CF_SQL_VARCHAR" maxlength="250">,
</cfif>
<cfif #image2Place# NEQ "">
image2 = <cfqueryparam value="#image2Place#" cfsqltype="CF_SQL_VARCHAR" maxlength="250">,
</cfif>
<cfif #image3Place# NEQ "">
image3 = <cfqueryparam value="#image3Place#" cfsqltype="CF_SQL_VARCHAR" maxlength="250">,
</cfif>
<cfif #image4Place# NEQ "">
image4 = <cfqueryparam value="#image4Place#" cfsqltype="CF_SQL_VARCHAR" maxlength="250">,
</cfif>
body = <cfqueryparam value="#form.body#" cfsqltype="CF_SQL_VARCHAR">
WHERE RecordID = <cfqueryparam value="#form.ID#" cfsqltype="CF_SQL_INTEGER" maxlength="50">
</cfquery>
编辑:这是我实现 fileExist() 后的新错误。此外,我看到所有这些图像都建立在我的服务器上。在其他照片中,我最多可以看到 sunset10.jpg。如果我让这个 fileExist 工作,它所做的不仅仅是防止显示错误并且永远不会执行删除。因为这些文件确实存在,除非我指向错误的位置。
Invalid CFML construct found on line 107 at column 138.
ColdFusion was looking at the following text:
>
The CFML compiler was processing:
An expression beginning with #, on line 107, column 23.This message is usually caused by a problem in the expressions structure.
A cfif tag beginning on line 107, column 18.
A cfif tag beginning on line 107, column 18.
A cfif tag beginning on line 107, column 18.
不幸的是,我无法打开强大的异常报告。此外,当我第一次导航到该页面时会显示此错误。在我有机会提交表格之前。同时,此代码位于 if 中,该 if 仅应在填写表格后执行。