Solved

Upload : Validating a File Name

Posted on 2013-01-09
5
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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