How to determine if a file upload is a valid CSV file — or at least text — in ColdFusion 8?

I have a form that allows the user to upload a file to the server. How to verify that a downloaded file is actually expected (CSV, or at least confirmation that it is a text file) in ColdFusion 8?

+5
source share
3 answers

For simple formats such as CSV, just test yourself, for example, using a regular expression.

 <cffile action="read" file="#uploadedFile#" variable="contents" charset="UTF-8">

 <cfset LooksLikeCSV = REFind("^([^;]*;)+[^;]*$", contents)>

You can put additional checks regarding file size restrictions or forbidden characters.

, .

- CSV ListToArray() CR/LF . XML , XmlParse(). , , , .

+4

I think this is as simple as specifying the accept value in cffile ... Unfortunately, CF8 docs do not indicate the value as part of the information for cffile ... It's under file management ...

<cffile action="upload" filefield="filename" destination="#destination#" accept="text/csv">

CF8 "File Type Control

0
source

All Articles