我正在尝试删除该文件,如果不是电子表格,但在上传testFile.text时不断收到以下错误: ColdFusion无法删除文件D:\ ColdFusion10 \ cfusion \ runtime \ work \ Catalina \ localhost \ tmp \ testFile.text
我验证了它不是权限问题,因为如果我返回并执行代码以尝试再次删除该文件,它将起作用。
<cffile action="upload" destination="#dest#" filefield="xlsfile" result="upload" nameconflict="makeunique">
<cfif upload.fileWasSaved>
<cfset theFile = dest & upload.serverFile>
<cfif isSpreadsheetFile(theFile)>
<cfspreadsheet action="read" src="#theFile#" query="data" headerrow="1">
<cfset showForm = false>
<cfelse>
<cfscript>
thisFile = theFile;
fileRead = createObject("java", "java.io.FileInputStream");
thisThread = CreateObject("java", "java.lang.Thread");
loopCT = 1;
while(1 EQ 1)
{
try
{
fileRead.init(thisFile);
break;
}
catch(any ecpt)
{
thisThread.sleep(1000);
}
incrementValue(loopCT);
if(loopCT GT 60)
{
fileRead.close();
return;
}
}
loopCT = 1;
while(1 EQ 1)
{
sizeA = fileRead.available();
thisThread.sleep(1000);
sizeB = fileRead.available();
if(sizeA EQ sizeB)
{
thisThread.sleep(1000);
sizeC = fileRead.available();
if(sizeC EQ sizeB)
{
break;
}
}
incrementValue(loopCT);
if(loopCT GT 60)
{
fileRead.close();
return;
}
}
fileRead.close();
<script type="text/javascript">
</script>
</cfscript>
<!--cffile action="delete" file="#theFile#"-->
<cfset errors = "The file was not an Excel file.">
<span style="font-size:medium;font-weight:bold; color:red"><p>The file was not an excel file!<p></span>
<input type="button" value="TRY AGAIN" class="button" onClick="window.location='bulk_upload.cfm'">
<br><br><br>
</cfif>
<cfset errors = "The file was not properly uploaded.">
</cfif>
答案 0 :(得分:0)
关于cfimage锁定文件并阻止删除,我遇到了完全相同的问题。我想出的解决方案如下。也许有人可以适应他们的情况:
<cflock name="[lockName]" timeout="5" >
<cfcache action="flush">
<!---[] Replace cfimage read function (CF BUG work around) --->
<cfscript>
imageObj = createObject( "java", "java.awt.Toolkit" );
imagetools = imageObj.getDefaultToolkit();
objImage = imagetools.getImage( "#fullpath#" );
<!---Whatever image I need from the image, or file...--->
<!---such as ---- myImageStruct["width"] = objImage.getWidth();--->
<!--- and then flush the object--->
objImage.flush();
</cfscript>
</cflock>