Solved

Upload : Validating a File Name

Posted on 2013-01-09
5
365 Views
Last Modified: 2013-01-09
Hi,
I have an aplication where the user will upload image files from their desktop and also specify the file name (not the path) for the image to be named on our server.  This will be used in a slider widget.

I'm not sure how to validate a proper Windows file name using CFFILE/Upload.  If it's invalid, will it just throw an error?  I guess I can use try/catch for that?  Is their a CF function (user or otherwise) to validate  Windows file name?

Thanks in advance,
hefterr
0
Comment
Question by:hefterr
  • 3
5 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 38760441
AFAIK there's no system function for that. I probably wouldn't bother inventing one. It's easier to do the try/catch and let windows tell you when it's wrong.

BUT .. do you really have to apply the file names they give you? What I usually do is apply the naming convention of my choice in code. Then store the user supplied name in the database. Then on download (or however they're presented to the user), I use the "pretty" name in the header. The users never know the difference.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38760490
> and also specify the file name (not the path) for the image to be named on our server

Ignoring the proper windows file name issue for a sec - what are you going to do if a file with that name already exists? ie Two users upload a picture named:  "myCar.jpg" OR the same user uploads two photos as "vacationPicture.jpg"?
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 38760562
no points here but +1 on agx's comments.

don't let your user name the file. You name it & control it, store the user's desired name separately.

I use createuuid() for file names to avoid uniqueness problems.
0
 
LVL 1

Author Closing Comment

by:hefterr
ID: 38760777
You are absolutely correct.  I will just name the images 000025.jpg, 0000026.jpg etc.  Any name the user enters I will store with the image name and display when needed.

I have to get rules for duplicates "names" - but I can never prevent them from uploading the same "image" - as even on their decktop, they could have multiple copies of the same image.

Thanks again
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38760828
>  I can never prevent them from uploading the same "image"

True, I phrased that poorly :) What I meant was entered the same file name "myCar.jpg" twice. So when you tried to save the file to disk, that name is already in use. But using your own naming convention avoids that altogether.

EDIT
>  I will just name the images 000025.jpg, 0000026.jpg etc

You might consider Sid's suggestion of using UUID instead. Then you don't have to worry coming up with unique file names!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question