School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,380 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,526 people online right now. Registration is fast and FREE... Join Now!




CFFIle destination dynamic file name extension

 

CFFIle destination dynamic file name extension, how do you preserve the native file extension while defining the file

coldiron

20 May, 2009 - 08:29 AM
Post #1

New D.I.C Head
*

Joined: 28 Mar, 2007
Posts: 7


My Contributions
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.

CODE

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.

CODE

<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?

User is offlineProfile CardPM
+Quote Post


cfdvlpr

RE: CFFIle Destination Dynamic File Name Extension

23 May, 2009 - 08:42 AM
Post #2

New D.I.C Head
*

Joined: 9 May, 2007
Posts: 5


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

xheartonfire43x

RE: CFFIle Destination Dynamic File Name Extension

28 May, 2009 - 12:32 PM
Post #3

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
QUOTE(coldiron @ 20 May, 2009 - 08: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.

CODE

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.

User is offlineProfile CardPM
+Quote Post

coldiron

RE: CFFIle Destination Dynamic File Name Extension

2 Jun, 2009 - 04:32 PM
Post #4

New D.I.C Head
*

Joined: 28 Mar, 2007
Posts: 7


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 09:29PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month