我的表单允许用户选择一个目录以查看其中包含的文件:
(files.cfm)
<form action="#buildURL('main.files')#" method="post">
<!--- Show the subfolder path, unless already at top level --->
<cfif subfolderPath EQ "">
<h2>You are at the top level.</h2>
<cfelse>
<h2>Current Folder: #subfolderPath#</h2>
</cfif>
<!--- Provide a drop-down list of subfolder names --->
Select folder:
<select name="subfolderPath" onChange="this.form.submit()">
<!--- Provide an option to go up one level to the parent folder, --->
<!--- unless already at the BaseFolder --->
<cfif listLen(subfolderPath, "/") gt 0>
<cfset parentFolder = listDeleteAt(subfolderPath, listLen(subfolderPath, "/"), "/")>
<option value="#parentFolder#">[parent folder]</option>
</cfif>
<!--- For each record in the query returned by <cfdirectory> --->
<cfloop query="DirectoryQuery">
<!--- If the record represents a subfolder, list it as an option --->
<cfif Type eq "Dir">
<option value="#subfolderPath#/#Name#">#Name#</option>
</cfif>
</cfloop>
</select>
<!--- Submit button to navigate to the selected folder --->
<input type="submit" value="go">
</form>
显示文件时,会有一个删除功能,该功能调用另一个页面:
<td align="absmiddle"><a href="#buildUrl('main.deleteFile?filename=#name#&folder=#rereplace(subFolderPath, '/','')#')#" onClick="alert('Are you sure you want to delete this file?')"><img src="/art/assets/images/delete.png" title="delete file" /></a></td>
在deletefile页面(deletefile.cfm)上,该文件已删除:
<cfset local.filePath = ExpandPath( ".uploadviewsfiles#rereplace(url.folder, '/','')#" ) />
<cffile action="delete"
file="#local.filePath##url.filename#"
/>
然后将用户发送回上一页:
<cflocation url="#buildUrl('main.files')#" />
,但不在刚刚删除文件的目录的同一视图中。我如何将用户返回文件页面并维护其目录的视图?
我可以想到几个方法
首先,您可以使用AJAX调用删除操作文件。成功完成后,请从当前页面中删除元素。这是一种花哨的方式,但可能很难实现,因为看起来您可能对此有些新。
第二,您可以将当前页面的上下文发送到删除文件(subfolderpath变量),当您重定向时将其添加到cflocation中。看起来您已经使用url.folder变量了,因此您可以执行此操作:
<cflocation url="#buildUrl('main.files', "subfolderPath=#rc.folder")#" />
看起来您使用的是FW/1,因此我假设" buildurl()"按广告宣传工作,并且您的URL&amp;形式变量在rc
范围中。
从CFLocation到达初始页面后,您将需要将选择放回已选择的文件夹上。在创建<option>
标签的循环中,添加检查以查看是否应该选择选项。我通常会做这样的事情:
<option value="..." <cfif listLast(rc.subFolderPath,"") EQ name>selected</cfif>>#name#</option>