【发布时间】:2012-06-21 01:37:42
【问题描述】:
我正在尝试创建一种搜索方法来在我的出站电子邮件中附加文件。我需要在文件夹中搜索并找到以某个字符开头的所有文件,然后将它们附加到电子邮件中。我只需要先了解如何创建这样的搜索方法,以便任何指向参考的指针或链接都将受到赞赏。
这是我目前所拥有的,但当我使用路径而不是 GetBaseTemplatePath() 时,它似乎无法正常工作
<cfscript>
attributes.attachments = 2011093475839213;
</cfscript>
<cfset Directory = "E:\sites\Example.com\FileFolder\#attributes.attachments#">
<cfset CurrentDirectory=Directory>
<cfset CurrentDirectory=ListDeleteAt(CurrentDirectory,ListLen(CurrentDirectory,"/\"),"/\")>
<cfoutput>
<b>Current Directory:</b> #CurrentDirectory#
<br />
</cfoutput>
<cfdirectory action="list" directory="#CurrentDirectory#" name="result">
<cfdump var="#result#">
当我稍微改变代码时
<cfset CurrentDirectory=GetBaseTemplatePath()>
我的代码有效,我得到了当前目录中所有文件的列表。我的路上是否有我看不到的错误?
这是我的 CFMAIL 部分,我确实有问题。
当我转储我的#result# 查询时,我得到了文件夹中的所有文件。然后我得到这个错误:
The resource 2011093475839213.pdf was not found.
The root cause was: ''.
尽管有错误,但我确实收到了一封电子邮件,只是没有收到附件。
<!--- Email Test --->
<CFMAIL FROM="user1@example.com" TO="user2@example.com" SUBJECT="Test" type="HTML">
<P> This is the attachment test</P>
<p> For this test to be successful, we need to receive some file attachments with this email</p>
<cfloop query="result">
<cfmailparam file="#result.name#" disposition="attachment">
</cfloop>
</cfmail>
<!--- Email Test Ends --->
【问题讨论】:
-
如果你这样做
<cfdump var=#DirectoryExists(CurrentDirectory)# />会发生什么?此外,您不需要ListDeleteAt的东西 - 使用getDirectoryFromPath -
我设法用 DirectoryExists 绕过它,毕竟我的路径确实有错误。我会尝试使用 getDirectoryFromPath,因为当涉及到子目录时我会遇到一些问题
-
我的
cfmailparam标记上出现错误The resource 2011093475839213.pdf was not found. The root cause was: ''.我正在转储查询并且该文件确实存在。我不知道为什么给我这个错误。 -
您没有指定目录。使用
#result.directory#/#result.name# -
@PeterBoughton 是的,错误是什么。谢谢