EasyCFM.COM ColdFusion Forums / General Discussion / File Name Format

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: File Name Format

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

epsnowden
12-06-2006 @ 5:45 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 16
Joined: Jun 2004

I have a coldfusion app that allows users to upload images. The
problem is that many of these users are not web savvy and upload hte
wrong types of images with terrible names. I have error handling in
place but would love to be able to disallow uploading of certian types
of files from within the cffile dialogue. Like only allow jpegs.

More importantly I am looking for a good name formatting function
that will strip out all the bad characters and spaces and truncate the
name and make sure they end with the proper extention. Is there
something out there that could do this? Thanks.

Eric

Webmaster
12-06-2006 @ 5:50 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

upload images only (that is part of the documentation) go here: http://www.cfquickdocs.com/?getDoc=cffileh (Pay close attention to the "accept" attribute).

As for file renaming... you can always use REReplaceNoCase() (documentation here: http://www.cfquickdocs.com/?getDoc=REReplaceNoCase)

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

epsnowden
12-06-2006 @ 6:03 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 16
Joined: Jun 2004

Is the accept attribute widely accepted (no pun intended)? It doesn't seem
to do anything in Safari. Haven't looked in other browsers yet.

And if I do REReplaceNoCase() won't I have to do multiple passes to get
multiple bad characters?

Webmaster
12-06-2006 @ 7:15 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

The first item; cffile processed at the server level. So your browser does not matter. Show us your code and we can help you as you go.

The second item, REReplaceNoCase uses Regular Expressions (hence the RE at the beginning Smile  )

So an example would be:
<cfset filename = REReplaceNoCase(cffile.serverFile, "[^A-Za-z0-9.\]", "", "ALL") />

That should replace anything that is not an A-Z or a-z or 0-9 or a "." with nothing (hence it will make it all go toghther Smile


Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email


Website Designed and Developed by Pablo Varando.