Link to home
Start Free TrialLog in
Avatar of hefterr
hefterrFlag for United States of America

asked on

Upload : Validating a File Name

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
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> 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"?
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.
Avatar of hefterr

ASKER

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
>  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!