CFFIle destination dynamic file name extension

how do you preserve the native file extension while defining the file

Page 1 of 1

3 Replies - 5596 Views - Last Post: 02 June 2009 - 05:32 PM Rate Topic: -----

#1 coldiron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-March 07

CFFIle destination dynamic file name extension

Posted 20 May 2009 - 09:29 AM

I am uploading an image and naming it in the destination attribute using a Session value & some fixed text, but I dont know how to preserve the file name extension so that I can edit the image using CfImage.

My action code looks like this, and it works.

cffile action="upload" destination="#ExpandPath('/images/homes' & '#SESSION.mm_listing_id#' & '_image1' & '.jpg')#" filefield="FORM.upload_file" nameconflict="overwrite" accept="image/*"/>



The problem comes when I try to resize the image. While the file uploads and renames the way I want, since I have defined the extension as .jpg, Coldfusion throws an error when the original image is not a jpg.


Here is the cfimage code that fails when I apply it to an image with an improper extension.

<cfimage action="resize" width="300" height="" source="#ExpandPath('/images/homes/#file.ServerFile#')#" destination="#ExpandPath('/images/homes')#" overwrite="yes">



The question is, can I name the uploading file in the destination attribute and maintain the files original extension so that I can later edit the file with CfImage?

Is This A Good Question/Topic? 0
  • +

Replies To: CFFIle destination dynamic file name extension

#2 cfdvlpr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-May 07

Re: CFFIle destination dynamic file name extension

Posted 23 May 2009 - 09:42 AM

You might want to use the convert action of cffile to actually convert the file to a jpeg. Renaming it with the .jpg extension is a bad idea.
Was This Post Helpful? 0
  • +
  • -

#3 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: CFFIle destination dynamic file name extension

Posted 28 May 2009 - 01:32 PM

View Postcoldiron, on 20 May, 2009 - 08:29 AM, said:

I am uploading an image and naming it in the destination attribute using a Session value & some fixed text, but I dont know how to preserve the file name extension so that I can edit the image using CfImage.

My action code looks like this, and it works.

cffile action="upload" destination="#ExpandPath('/images/homes' & '#SESSION.mm_listing_id#' & '_image1' & '.jpg')#" filefield="FORM.upload_file" nameconflict="overwrite" accept="image/*"/>



The problem comes when I try to resize the image. While the file uploads and renames the way I want, since I have defined the extension as .jpg, Coldfusion throws an error when the original image is not a jpg.


Here is the cfimage code that fails when I apply it to an image with an improper extension.


The question is, can I name the uploading file in the destination attribute and maintain the files original extension so that I can later edit the file with CfImage?


I think there is a variable called #cffile.fileext# do a dump a the cffil variable and see if there are any variables that isolate the extension.
Was This Post Helpful? 0
  • +
  • -

#4 coldiron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-March 07

Re: CFFIle destination dynamic file name extension

Posted 02 June 2009 - 05:32 PM

Thanks for the note. You were on the right track. I was able to save the file.fileserverext as a variable and use it in the destination statement. That solved that problem
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1