Skip to main content
September 29, 2008
Question

cffile accept

  • September 29, 2008
  • 1 reply
  • 271 views
I just added the accept parameter to my cffile. The attributes that I specify work good but when I try to upload a file that is not listed as an attribute it errors out.

Error = Element SERVERFILE is undefined in CFFILE.

Seems like I would need some error handling in here but not sure where.

Any help would be appreciated.
    This topic has been closed for replies.

    1 reply

    Inspiring
    September 29, 2008
    the way i usually do it is:

    in your action page code:
    <cfset imgsuccess = false>
    <cfif len(trim(form.imagefile))><!--- makes sure the code executes only
    if a file has ben selected in the form --->
    <cftry>
    <cffile
    action = "upload"
    filefield = "imagefile"
    destination =
    "d:/hshome/justinnickrand/thumbshopping.com/betathumbshopping/custimage"
    accept="image/pjpeg, image/jpeg, image/jpg, image/gif"
    nameConflict = "MakeUnique">
    <cfset imgsuccess = true>
    <cfcatch>
    <cfset imgsuccess = false>
    </cfcatch>
    </cftry>
    <cfif imgsuccess is true>
    <!--- your update query here --->
    </cfif>

    that's the very basics. no error reporting, no user-friendly error
    messages. you can add those as necessary.

    since it seems that you do not see the CF error about wrong file type,
    it makes me think you already have some sort of error trapping in place
    that suppresses cf errors display and makes your <Cffile> fail
    silently... otherwise cf would have displayed you its blue-grey error
    about a wrong file type...

    my code above will at least not try to update your db if CFFILE code did
    not succeed.



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