Thanks, Justin and Peter...

I've rarely used the ReReplace function, so I had forgotten
about that one...duh...

Also, Peter, My regex below works because, well, I lied.  No, not really.
The code I put below left off one *very* important detail.  The code I'm 
actually using uses cffile.serverFileName instead of just cffile.serverFile

So I'm just running the regex on the part of the filename before the
extension.

I have to separate the filename from the extension into two variables so I
can
add some characters to the end of the filename before the extension.

Here's the full code that I'm running to get the filenames to where I can
use them:

<cffile action       = "upload"
        filefield    = "#strField#"
        destination  = "#expandPath( 'files/' )#"
        accept       = "image/jpg, image/pjpg, image/jpeg, image, pjpeg"
        nameConflict = "makeUnique" />

<cfset  renamedOriginal = reReplace(#cffile.serverFileName#,
'[^a-zA-Z0-9.]', '', 'all') />

<cffile action       = "rename"
        source       = "#expandPath( 'files/#cffile.serverFile#' )#"
        destination  = "#expandPath(
'files/#reReplace(cffile.serverFileName,
                       '[^a-zA-Z0-9.]', '',
'all')#.#cffile.serverFileExt#")#" />

Then, to create various sizes of the file, I use code like:

<cffile action       = "resize"
        height       = ""
        width        = "200"
        source       = "#expandPath(
'files/#renamedOriginal#.#cffile.serverFileExt#' )#"
        destination  = "#expandPath(
'files/#renamedOriginal#_200.#cffile.serverFileExt#' )#"
        overwrite    = "yes" />

Then, to create the fieldname for the database insertion:

<cfset  client_photo_200 = "#renamedOriginal#_200.#cffile.serverFileExt#" />

And the same for other sizes as needed.

If you have some tips on how this could be optimized, I'm all ears.
I'm just glad to finally have this code working!

Thanks, again!

Rick
        

> -----Original Message-----
> From: Peter Boughton [mailto:[email protected]]
> Sent: Friday, March 13, 2009 10:22 PM
> To: cf-talk
> Subject: Re: How can I make this "Replace()" work?
> 
> 
> ><cfset renamedOriginal = regex.replace(cffile.serverFile, "[^a-zA-Z0-
> 9.]",
> >"")>
> 
> ColdFusion does not have a built in "regex" object, as you are
> attempting to use there.
> 
> To perform a regex replace, you need to use
> rereplace("input","regex","replacement")
> 
> 
> Also, your regex does not match your description:
> > something to remove all non-alphanumeric characters,
> > except the . before the extension.
> 
> You are currently accepting any . not just the last one.
> 
> Try this instead:
> 
> <cfset Extension = ListLast(cffile.ServerFile,'.')/>
> <cfset NewFilename = rereplace( cffile.ServerFile ,
> "\W|(\.#Extension#$)" , '' , 'all' ) &'.'& Extension />
> 
> (Not that is not perfect, but should be good enough for your needs)
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:320518
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to