Solved

Upload : Validating a File Name

Posted on 2013-01-09
5
359 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
Comment Utility
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_
Comment Utility
> 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
Comment Utility
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
Comment Utility
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_
Comment Utility
>  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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

15 Experts available now in Live!

Get 1:1 Help Now