Shaun Mccran

My digital playground

07
M
A
Y
2010

ImageCFC losing file permissions on image manipulation

This article deals with a work around for a problem I had been experiencing with the imageCFC ( http://www.opensourcecf.com/imagecfc/ ) open source project. When resizing an image the file permissions were being lost on the edited file. This meant that the server operating system could not read or serve up the file to the browser.

I've been using imageCFC as I have a variety of coldfusion server versions (7 and 8), and I like the fact that in the resize method you can specify the maximum size for the width and height, and it will resize down to that size, and keep the aspect ratio of width-to-height.

The routine I am using here will upload an image (cffile), make a copy and resize that copy as a thumbnail (imageCFC), then using cffile we will re-copy the file, restoring its file permissions.

Firstly we will start off by uploading the file using the tried and tested cffile tag.

view plain print about
1<cffile action="upload"
2destination="#imageDestination#"
3nameconflict="error"
4filefield="form.imageField">

Next I create a unique id to use as the file name, and create two variables. The first is a fake variable that we will use and destroy later. The second is the name of the file we are going to store permanently.

view plain print about
1<cfset uniqueId = CreateUUID()>
2
3<!--- create thumb --->    
4<cfset fakeThumbDestination = destinationThumbDir & '\' & uniqueId & '_temp.' & ext>
5<cfset realThumbDestination = destinationThumbDir & '\' & uniqueId & '_thumb.' & ext>

Next we will use imageCFC to copy and resize the image to a thumbnail. This is constrained to a maximum of 135 in either dimension. This code reads the original uploaded file, and resizes it and saves it into a different directory.

view plain print about
1<cfset application.imageCFC.resize("", imageDestination, fakeThumbDestination, 135, 135, true)>

If we were to look at this file now we would see that all the server and IIS permissions are missing. They are supposed to be inherited from the parent folder, but in my environment they are not. So we need to put them back.

We can use cffile to make a copy of out thumbnail image, and write it back out as the correct filename, then delete the file that has no permissions.

view plain print about
1<cffile action="copy"
2source="#fakeThumbDestination#"
3destination="#realThumbDestination#">

4
5<!--- delete the fake file --->
6<cffile action="delete" file="#fakeThumbDestination#">

When we copy the file the parent folder permissions are re-applied and IIS can read the file again.

It feels a bit hacky, but I can't find any other work around for imageCFC.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top