• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cffile accept

Guest
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

Hi i have a file upload which i need to only accept CSV files, i have 2 problems with the code below

1. i have tried uploading a csv file but i get an error, do i need to add more to the accept clause?

2. if a user uploads a differnent mime type how can i do a <cfif file ext is not csv redirection>

<cffile action="upload" filefield="FILE" destination=#currentdir# nameconflict="makeunique" accept="CSV">
TOPICS
Advanced techniques

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Mar 14, 2007 Mar 14, 2007
that works ok, accept, i get the error when i actually upload a .csv file?

i created a csv file from micosoft excel, and it will not allow it to be uploaded any ideas why?

Votes

Translate

Translate
LEGEND ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

formal mime type for csv files is text/csv
so change accept="CSV" to accep="text/csv"
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

ok thanks,

how do i now use a cfif tag to redirect the user if he tries to upload a jpeg etc,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

craiglaw98 wrote:
> ok thanks,
>
> how do i now use a cfif tag to redirect the user if he tries to upload a jpeg etc,

if you want to do it in CF, then you will have to use <cftry>/<cfcatch>
structure to catch the error cffile will trow when a user tries to
submit a wrong mime type file. i don't quiet remember which exception is
thrown (i think it is application) - will look it up at work and post
back...

--
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

ok thanks

i found this code, do this help

Error Handling File Manipulations

Now, as I discussed in my error handling article, file manipulations can be sketchy creatures. Sometimes they don't work as we intend them to. They can also be very, very dangerous. So, I recommend wrapping each and every file manipulation in it's own try/catch block. (Don't package two of them in the same block, it will be much more difficult to trace, believe me. It's worth the little extra bit of effort.)

<cftry>
<cffile action="read" file="#newDir#test1.txt" variable="myVar">
<cfcatch>
<!--- genius bit of error logging here --->
</cfcatch>
</cftry>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

yes, that's exactly what you should use. i have checked and the wrong
mime type throws exception of application type, so:

<cftry>
<cffile action="upload" destination="somefolder"
filefield="form.yourfilefieldnamehere" accept="text/csv"
nameconflict="whichever_option_you_use">
<cfcatch type="application">
your wrong file type handling code goes here. depends on how you want to
handle it: show an error message on the same page and cancel form
submitting or redirect to some error page or whaever you want to do.
</cfcatch>
</cftry>
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

that works ok, accept, i get the error when i actually upload a .csv file?

i created a csv file from micosoft excel, and it will not allow it to be uploaded any ideas why?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

LATEST
if it was created from excel, then maybe it has excel mime type even
though it is a csv file... try using in your <cffile>:

accept="text/csv,application/msexcel"

or maybe accept="text/csv,application/csv" will work too...

these are mime type associated with csv files:
text/comma-separated-values
text/csv
application/csv
application/excel
application/vnd.ms-excel
application/vnd.msexcel
text/anytext

(reference: http://filext.com/detaillist.php?extdetail=CSV)

all of them should work. since csv files can be created with various
applications, exact mime tupe of a csv file will probably depend on the
application it was created with... i am just guessing here, though...

hope this helps

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation