From: hans blix on
I'm having a problem with CFImage where it seems to be locking the image file
it is using, making it unable to be deleted (even in windows file explorer).

Here is the scenario:
I upload an image file using cffile action=upload

I read the file in using cfimage

I resize the file (using imageResize()) and write it to disk using CFImage
action="write" with a new file name.

I then try to delete the original uploaded file, and get an error:
ColdFusion could not delete the file
d:\inetpub\wwwroot\site\cfml\images\listingimages\1998\000_0202.jpg for an
unknown reason.

The reason appears to be that ColdFusion had locked the file. It only seems to
happen with files over 300K in size.

I've tried everything I can think of to delete the file. Some have stayed
locked and unable to delete until I restart the CF services.

I'm running CF8.0.1 on Win2003 server. Thanks for any help you can give.

From: TKirstein on
We have noticed the same issue in the same type environment (CF8.0.1 on Win2003
server).

For us, it seems to lock the source image no matter the size of the jpg.
After the file is uploaded, we try to resize it and then write the image back
out to the same filename (with overwrite="true"). This causes an error.
Resizing to a different filename works.

For us it seems any JPG image that is used as the source in a cfimage resize
will be left locked.

We have tried using cfimage with source and destination set (as the same JPG
file name with OS path) and Overwrite set to true (RESULT: Errors out with
"Ensure that the destination directory exists and that Coldfusion has
permission to write to the given path or file. cause :
java.io.FileNotFoundException").

We have tried resizing the image into memory then tried to cffile delete the
source file... wanting to write the image back to the drive from memory
(RESULT: errors out saying the file cannot be deleted)

What we have done for now is to rename the file to a XXXXX_TEMP.JPG temp file
and resize it to the needed destination. Works perfectly but leaves behind
_TEMP.JPG files that cannot be deleted due to a file lock.

As Administrator on the server we cannot delete or rename the source file for
about 30-45 minutes after the resize is completed (or we restart the ColdFusion
service)

Any work around or fixes to this issue would be greatly appreciated.

TIA

From: rhall on
We are also seeing this same behavior. It seems to have just started
in the last month or so, I believe our customer's host must have
applied an update to the CF servers.

If I change my code to upload the new image to the cftemporary
directory, does anyone know how often that directory is automatically
cleared, if at all.

Thanks,
From: DefconRhall on
We have this same issue. It seems to happen with every image now.

I believe it has something to do with a recent CF update that one of our
customer's hosting providers has applied, however they do not know which it is.

I was thinking of a fix involving uploading the new file to the CFTemporary
directory. However I was wondering if and how often the CFTemp directory is
purged automatically.

From: hans blix on
We came up with a workaround since the issue seems to be a bug. We are now
uploading to a directory, reading the file and resizing, then saving it to a
different directory (leaving us with 2 files). This way the original file can
stay locked because we never write to it. To get rid of the original files in
that directory, we run the attached code nightly as a scheduled task to purge
any images from that upload directory that haven't been accessed in the last 30
minutes. The files seem to unlock after a period of time, so deleting them
hasn't been a problem. So far this workaround has done the job.

Please post back if you found a better solution or a fix.

<cfset variables.uploadPath = "d:\myUploadDirectoryPath\"/>
<cfdirectory action="LIST" directory="#variables.uploadPath#"
name="qUploadsDir">
<cfloop query="qUploadsDir">
<!--- Make sure the image wasn't just uploaded and potentially in use by the
system --->
<cfif dateDiff("n",qUploadsDir.dateLastModified,now()) gt 3>
<cffile action="delete" file="#variables.uploadPath##qUploadsDir.name#"/>
</cfif>
</cfloop>