如何在服务器上复制文件?
我可以用<cffile action="read">
阅读它,但我想以新名称复制它。
我找到<cffile action="copy">
但我只能将它复制到另一个目录。我需要在同一目录中复制它。
日Thnx。
答案 0 :(得分:4)
不,<cffile action="copy">
可以在与现有文件相同的目录中创建副本。只要您使用不同的文件名。所以如果你不能这样做,别的东西就有问题了。请发布您的代码和任何错误消息。
答案 1 :(得分:1)
未经测试但一个选项可能是将文件读取为二进制文件,然后将其写入新文件。
从Adobe文档底部采取的示例: - http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_f_08.html
<cffile action = "readBinary" file = "C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere.jpg" variable = "aBinaryObj">
<!--- Output binary object to JPEG format for viewing. --->
<cffile action="write" file = "c:\files\updates\somewhereB.jpg" output = "#toBinary(aBinaryObj)#">
<!--- HTML to view image. --->
<img src="C:\files\updates\somewhereB.jpg">
答案 2 :(得分:1)
接受的答案使其复杂化。 这就是你所需要的:
<cffile action="COPY" source="C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere.jpg" destination="C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere_Copy.jpg">