Skip to main content
Inspiring
November 2, 2008
Question

CFFILE question

  • November 2, 2008
  • 8 replies
  • 1158 views
I am trying to allow users to upload a logo along with some information.

So, on the form, I have:


<cfform action="CF/addLink.cfm" method="post" preloader="no" lang="en" dir="ltr"
title="test" enctype="multipart/form-data">
Select the type of link you are adding:<br> Club <cfinput type="radio"
name="type" visible="true" checked="true" value="1"> Equpiment vendor/reseller
<cfinput type="radio" name="type" visible="yes" checked="no" value="2"><br>
<table width="95%" border="0">
<tr>
<td>Link Contact Person:</td>
<td><cfinput type="text" name="linkContact" size="25" maxlength="30"></td>
</tr>
<tr>
<td>Club Address:</td>
<td><cfinput type="text" name="linkAddress" size="30" maxlength="40"></td>
</tr>
<tr>
<td>Club City:</td>
<td><cfinput type="text" name="linkCity" size="15" maxlength="20"></td>
</tr>
<tr>
<td>Club State:</td>
<td><cfinput type="text" name="linkStat" size="2" maxlength="2" style="text-transform:uppercase"></td>
</tr>
<tr>
<td>Club Zip:</td>
<td><cfinput type="text" name="linkZip" size="5" maxlength="5"></td>
</tr>
<tr>
<td>Upload a club logo?</td>
<td><cfinput type="file" name="linkLogo"></td>
</tr>
</table>

<p align="center"><cfinput type="submit" name="Submit" value="Submit"></p>

</cfform>

and on the processing page:

<cfparam name="form.linkLogo" default="">
<cfif len(form.linkLogo) gt 1>
<cfset upDir=expandpath("logos")>
<cffile action="upload" filefield="form.linkLogo" destination="#upDir#" nameconflict="makeunique"
mode="777">
</cfif>

The problem is, the file doesn't appear to be uploading, but there isn't
any error either.........


    This topic has been closed for replies.

    8 replies

    Inspiring
    November 5, 2008
    Just to test to see if you are passing all the form vars correctly, on your processing page, do a dump of the form vars and see what it is passing and not passing. You might not be passing them right:

    <cfdump var"#form#">

    and also just strip out all the other code and see if it will upload an image with no conditions present:

    <cffile action="upload" filefield="form.linkLogo" destination="c:\pathtofolder\foldername">

    Then check to see if the file is not there. If not, you may have a path or permissions issue.

    Inspiring
    November 3, 2008
    > I agree with you there is some ambiguity. But I think that, here,
    > name("linkLogo") and qualified name("form.linkLogo") mean the same thing.

    Well that clears that. I decided to pull my head out of my arse and run
    the code.

    Two things:
    1) the form field thing is fine. It's the variable it's after not the HTTP
    field.
    2) the code runs fine for me.

    Steve, what do yuo get if you dump out the CFFILE struct after the upload?
    Any clues in there?

    Also, reviewing things further, it seems like fairly poor practice to me to
    have your logo files stored in the same vicinity as your source code (a
    subdir, in this case). It would be better to keep that sort of thing
    separated out in an "assets" (or "pics", "graphics", "images" or whatever)
    completely separate from your code files. This is nothing to do with your
    problem here, though.

    --
    Adam
    BKBK
    Community Expert
    Community Expert
    November 3, 2008
    >> I don't know what you mean by that. "Lang", "dir" and "title"
    >> are neither valid attributes of the HTML form tag.

    > The W3C seem to disagree with you there
    You're right. My bad. I've confirmed that they're indeed valid HTML form attributes, hence valid cfform metadata.

    > So it's not the form-scoped variable they're wanting there.
    > Sure the form-scoped variables hold the values off the HTTP
    > form fields, but they're not necessarily the same thing.


    I agree with you there is some ambiguity. But I think that, here, name("linkLogo") and qualified name("form.linkLogo") mean the same thing.

    > It's not a self-posting form template.
    I have no answer to that really. Didn't see this until now: "and on the processing page"

    Inspiring
    November 3, 2008
    > Adam Cameron wrote:
    > I think it's safe to assume that the "processing page" that the OP mentions
    > is in fact CF/addLink.cfm.

    > I suspect not. That looks to me like a path relative to, and away from, the
    > current page.

    Yes. That was my point. The OP *said* it was a different template in his
    original post. It's not a self-posting form template.


    > The docs suggest it ought to be just filefield="linkLogo"
    > True. However, 'form' is an optional scoping prefix, so I expect
    > filefield="form.linkLogo" to work.

    A "scope" only comes into it if that value is a reference to a variable. I
    was wondering it if was a reference to the HTTP form field (not quite the
    same). But I don't know, so am not going to push the point. It's
    something to try, that's all. The OP's code is different from the example
    code, that's all.

    What made me wonder was the wording of the docs:

    {quote}
    Name of form field used to select the file.

    Do not use number signs (#) to specify the field name.
    {quote}

    So it's not the form-scoped variable they're wanting there.

    Sure the form-scoped variables hold the values off the HTTP form fields,
    but they're not necessarily the same thing.


    > They're not specifically implemented by <cfform>, but they are valid HTML
    > attributes.

    > I don't know what you mean by that. "Lang", "dir" and "title" are neither
    > valid attributes of the HTML form tag.

    The W3C seem to disagree with you there:
    http://www.w3.org/TR/html401/interact/forms.html#h-17.3

    --
    Adam
    BKBK
    Community Expert
    Community Expert
    November 3, 2008
    Adam Cameron wrote:
    I think it's safe to assume that the "processing page" that the OP mentions is in fact CF/addLink.cfm.
    I suspect not. That looks to me like a path relative to, and away from, the current page.

    The docs suggest it ought to be just filefield="linkLogo"
    True. However, 'form' is an optional scoping prefix, so I expect filefield="form.linkLogo" to work.

    They're not specifically implemented by <cfform>, but they are valid HTML attributes.
    I don't know what you mean by that. "Lang", "dir" and "title" are neither valid attributes of the HTML form tag.





    Inspiring
    November 3, 2008
    just to add to all the above:
    your upload code will be looking for a 'logos' sub-folder in the folder
    of your form's action page, specifically it will be looking for CF\logos
    folder to save the file to.

    also, unless you are on a *nix system, you do not need the MODE
    attribute in cffile tag.

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    November 3, 2008
    > 1) "Lang", "dir" and "title" are not valid attributes of
    > http://livedocs.adobe.com/coldfusion/8/Tags_f_13.html.

    They're not specifically implemented by <cfform>, but they are valid HTML
    attributes. These are simply passed through and spat out the other side
    when CF is generating the <form> tags.

    This is detailed on at the URL you cite, in the "history" section (under
    "ColdFusionMX 7").


    > 2) Your code suggests that the form's action page is the current page, not
    > "CF/addLink.cfm". Use "#cgi.script_name#" instead.

    I think it's safe to assume that the "processing page" that the OP mentions
    is in fact CF/addLink.cfm. Given he makes a point of distinguishing
    between the form template and the processing one, I think suggesting
    submitting the form to itself might be a bit of a bum steer.


    I would think it would give an error if I'm right about this, but is using
    filefield="form.linkLogo" correct? The docs suggest it ought to be just
    filefield="linkLogo" (ie: the name of the form field, not the name of the
    form variable). I gotta say I don't often find myself writing file-upload
    code, so don't know off the top of my head (and am not in a position to
    check for myself just now). But, like I said, I'd expect an error if CF
    didn't like that. No harm in checking, though.

    It might also be an idea to check your various variables to make sure they
    have the values you expect them to. EG: form.linkLogo and upDir.

    --
    Adam
    BKBK
    Community Expert
    Community Expert
    November 3, 2008
    1) "Lang", "dir" and "title" are not valid attributes of <cfform>.

    2) Your code suggests that the form's action page is the current page, not "CF/addLink.cfm". So use "#cgi.script_name#" instead.

    3) You must create the logos directory beforehand.

    4) Use the accept attribute of <cffile action="upload"> to specify the acceptable MIME types to be uploaded, for example, accept="image/jpeg, image/pjpeg, image/gif, application/pdf". Optional, but recommended.