Professional Web Applications Themes

make cffile optional? - Coldfusion - Advanced Techniques

I have created a page where people can upload screen shots of error messages.. now how can I make the field optional (i.e. Saving empty (zero-length) files) as it's not mandatory? code is below: <cfif IsDefined("form.file")> <cfset thisPath = ExpandPath("*.*")> <cfset thisDirectory = GetDirectoryFromPath(thisPath)> <cffile action="UPLOAD" filefield="file" destination="#thisDirectory#" nameconflict="OVERWRITE"> <cfelseif cffile.fileWasSaved IS "Yes"> <h1>File successfully uploaded</h1> <cfelseif cffile.fileWasSaved IS "No"> <h1>Error uploading file</h1> </cfif>...

Sponsored Links
  1. #1

    Default make cffile optional?

    I have created a page where people can upload screen shots of error messages..
    now how can I make the field optional (i.e. Saving empty (zero-length) files)
    as it's not mandatory?

    code is below:

    <cfif IsDefined("form.file")>

    <cfset thisPath = ExpandPath("*.*")>
    <cfset thisDirectory = GetDirectoryFromPath(thisPath)>
    <cffile action="UPLOAD" filefield="file" destination="#thisDirectory#"
    nameconflict="OVERWRITE">
    <cfelseif cffile.fileWasSaved IS "Yes">
    <h1>File successfully uploaded</h1>
    <cfelseif cffile.fileWasSaved IS "No">
    <h1>Error uploading file</h1>
    </cfif>

    Sponsored Links
    cobramichelle Guest

  2. #2

    Default Re: make cffile optional?

    Unless you have a reason for saving a zero length file, I would check the
    length of the form field and if it it is empty, skip the upload.

    Also, "FILE" is a reserved word. You might consider changing the form field
    name to something else (eg. form.uploadFileName). This will help avoid
    potential problems or conflicts when referring to that variable without a scope.

    <cffile action="UPLOAD" filefield="file" destination="#thisDirectory#" ...>

    mxstu Guest

  3. #3

    Default Re: make cffile optional?

    Thanks a bunch mxstu

    question:
    I am saying if less than one.. to just display a message saying "thank you"
    after the following line
    <cfif LEN("form.uploadFileName") LT 1>
    say "thank you"


    then


    <cfelseif LEN("form.uploadFileName") GT 1>
    ..upload the file..

    ** uploading works fine.. when I have no doent to upload I still get the
    "no zero length" -




    cobramichelle Guest

  4. #4

    Default Re: make cffile optional?

    > <cfif LEN("form.uploadFileName") LT 1>

    Remove the quotes around the form field name. By using double quotes here
    you're checking the length of the literal string "form.uploadFileName", not the
    form field value. Try:

    <cfif LEN(form.uploadFileName) EQ 0>
    Thanks
    <cfelse>
    ... upload the file
    </cfif>

    mxstu Guest

  5. #5

    Default Re: make cffile optional?

    That worked, thank you so much. I appreciate it ;-)
    cobramichelle Guest

Similar Threads

  1. Optional Arguments in a CFC
    By Cannikinn in forum Coldfusion - Advanced Techniques
    Replies: 3
    Last Post: June 22nd, 09:16 PM
  2. numberformat - is optional no longer optional?
    By miki in forum Macromedia ColdFusion
    Replies: 1
    Last Post: April 18th, 11:07 PM
  3. Optional properties
    By Alex Dinu in forum ASP.NET Web Services
    Replies: 4
    Last Post: December 21st, 04:25 PM
  4. preg_match_all optional subpattern
    By Han in forum PHP Development
    Replies: 5
    Last Post: October 7th, 05:50 PM
  5. How to make an argument optional...confirmation...
    By Jonathan Villa in forum PHP Development
    Replies: 2
    Last Post: August 22nd, 03:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139