Solved

Upload : Validating a File Name

Posted on 2013-01-09
5
361 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now